javascriptgraphqlgraphql-js

graphqljs - Query root type must be provided


How do I get around this error? For this particular schema, I do not need any queries (they're all mutations). I cannot pass null and if I pass an empty GraphQLObjectType it gives me the error:

Type Query must define one or more fields.

Solution

  • If you're using graphql-tools (maybe other SDL tools too), you can specify an empty type (such as Query) using:

    type Query
    

    Instead of

    type Query {}
    

    If you're building the schema programatically you'll have to add dummy query, much like:

    new GraphQLObjectType({
      name: 'Query',
      fields: {
        _dummy: { type: graphql.GraphQLString }
      }
    })
    

    Which is the programmatic equivalent of the SDL:

    type Query {
      _dummy: String
    }