Search code examples
graphqlapollo

GraphQLError: Syntax Error: Expected :, found { Probably a syntax error


I am getting this error: GraphQLError [Object]: Syntax Error: Expected ":", found "}", while I am trying to build out a GraphQL Server using Apollo and will eventually host on MongoDB.

But I cannot understand why, can someone maybe spot a mistake in my code?


const gameWeek = gql`
    type Query {
        GameWeeks: [GameWeek]!
    }
    type Mutation {
        createGameWeek(player_id: ID!): GameWeekUpdateResponse!
        updateGameWeek(player_id: ID!): GameWeekUpdateResponse!
        deleteGameWeek(player_id: ID!)
    }
    type createGameWeek {
        player_id: ID!
        player_name: String!
        points: Float
        rank: Int!
        previous_rank: Int!
        total: Float
        team_name: String!
        team_id: Int
    }
    type GameWeekUpdateResponse {
        success: Boolean!
        message: String
        gameweeks: [GameWeek]
    }
    type GameWeek {
        player_id: ID!
        player_name: String!
        points: Float
        rank: Int!
        previous_rank: Int!
        total: Float
        team_name: String!
        team_id: Int
    }
`;

module.exports = gameWeek;```

Solution

  • in the 8th line you have:

    deleteGameWeek(player_id: ID!)
    

    the error explains u that u have to write what your mutation will return by a ":" and the type of data like "Boolean", the compiler just found a "}" after the mutation declaration. You can't let a Query, Mutation or Subscription without a return value(maybe with scalar but that is another history).

    a correct declaration could be:

    deleteGameWeek(player_id: ID!) : GameWeekUpdateResponse!