Search code examples
graphqlapollo-clientapollo-servergraphql-js

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


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