Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GraphQLError: Syntax Error: Unexpected "("

I am new to GraphQL and am trying to query the TfL API for a project with React. I am trying to pass $arrival as a variable into the query, dynamically calling arrivals by station ID. It was working yesterday but this morning it is throwing a syntax error, any ideas where it may be coming from?

Type Defs

const typeDefs = `
  type Station {
    id: String!
    stationName: String
    lineId: String
    lineName: String
    platformName: String
    direction: String
    timestamp: String
    timeToStation: Int
    currentLocation: String
    towards: String
    expectedArrival: String
    modeName: String
  }
  
  type Query($arrival: String!) {
    getArrivals(id: $arrival): [Station]
    station: [Station]
  }
`;

Query

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


const GET_ALL_ARRIVALS = gql`
  query Arrivals($id: String!) {
    getArrivals(id: $id) {
      id
      stationName
      platformName
      lineName
      towards
      timeToStation
    }
  }
`;

>Solution :

Try changing your schema to

const typeDefs = `
  type Station {
    id: String!
    stationName: String
    lineId: String
    lineName: String
    platformName: String
    direction: String
    timestamp: String
    timeToStation: Int
    currentLocation: String
    towards: String
    expectedArrival: String
    modeName: String
  }
  
  type Query {
    getArrivals(id: String!): [Station]
    station: [Station]
  }
`;

That doesn’t explain the error, but it seems wrong to me in comparison to the documentation

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading