James Bender
James Bender

Reputation: 1232

Having issues with a GraphQL schema in Apollo

I'm building an Express server with Apollo 2. I have the following schema:

const typeDefs = gql `{     
    type Movie {
      id: ID!
      title: String
      year: String
      rating: String      
    }

    type Query {
      movies: [Movie]
    }
  }`;

When I run the app, I am getting this error:

GraphQLError: Syntax Error: Expected Name, found !

Here's the list of packages I am using (irrelevent packages removed):

"apollo-server-express": "^2.8.2", "body-parser": "^1.19.0", "express": "^4.17.1", "graphql": "^14.4.2", "graphql-tools": "^4.0.5",

I've done this with version 1 and had no issue. Am I missing a package? Is there a typo or change in the syntax that I missed? I've been looking at this for a couple of hours and cannot figure what the problem is.

Thanks, James

Upvotes: 2

Views: 180

Answers (1)

Daniel Rearden
Daniel Rearden

Reputation: 84687

There is no need to wrap your document with a pair of curly brackets. It should just be

const typeDefs = gql`     
  type Movie {
    id: ID!
    title: String
    year: String
    rating: String      
  }

  type Query {
    movies: [Movie]
  }
`

When using SDL, curly brackets are only used when specifying a list of fields or the values of an enum.

Upvotes: 4

Related Questions