Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphQLError: Query root type must be provided

I'm using NestJS, TypeORM and GraphQL for my backend API. I'm getting the following error:

GraphQLError [Object]: Query root type must be provided.
      at SchemaValidationContext.reportError (/home/wise-introvert/Container/Projects/the-notebook/app/server/node_modules/graphql/type/validate.js:88:19)
      at validateRootTypes (/home/wise-introvert/Container/Projects/the-notebook/app/server/node_modules/graphql/type/validate.js:107:13)
      at validateSchema (/home/wise-introvert/Container/Projects/the-notebook/app/server/node_modules/graphql/type/validate.js:52:3)
      at graphqlImpl (/home/wise-introvert/Container/Projects/the-notebook/app/server/node_modules/graphql/graphql.js:79:62)
      at /home/wise-introvert/Container/Projects/the-notebook/app/server/node_modules/graphql/graphql.js:28:59
      at new Promise (<anonymous>)
      at Object.graphql (/home/wise-introvert/Container/Projects/the-notebook/app/server/node_modules/graphql/graphql.js:26:10)
      at GraphQLSchemaFactory.<anonymous> (/home/wise-introvert/Container/Projects/the-notebook/app/server/node_modules/@nestjs/graphql/dist/schema-builder/graphql-schema.factory.js:49:52)
      at Generator.next (<anonymous>)
      at /home/wise-introvert/Container/Projects/the-notebook/app/server/node_modules/tslib/tslib.js:114:75

This is what my file structure and code looks like: enter image description here

Can someone please help me. My repo: https://github.com/wise-introvert/nestjs-graphql-api.git

like image 640
Fardeen Panjwani Avatar asked Sep 28 '20 16:09

Fardeen Panjwani


People also ask

What is root query in GraphQL?

Root fields & resolvers At the top level of every GraphQL server is a type that represents all of the possible entry points into the GraphQL API, it's often called the Root type or the Query type. In this example, our Query type provides a field called human which accepts the argument id .

How do you define schema in GraphQL?

A GraphQL schema is a description of the data clients can request from a GraphQL API. It also defines the queries and mutation functions that the client can use to read and write data from the GraphQL server. In other words, you specify your client or application UI data requirements in your GraphQL schema.


1 Answers

All servers running with GraphQL must have at least one @Query() to be considered a valid GraphQL server. Without it, the apollo-server package will throw an exception and the server will fail to start. This can be as simple as

@Resolver()
export class FooResolver {

  @Query(() => String)
  sayHello(): string {
    return 'Hello World!';
  }
}
like image 120
Jay McDoniel Avatar answered Sep 22 '22 18:09

Jay McDoniel