Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apollo GraphQL Error: Query root type must be provided

Tags:

graphql

apollo

I have an Angular/Apollo GraphQL implementation generating typescript code based on GraphQl endpoint which is surfacing a schema. I can hit the endpoint via Postman with a query and results are returned. However, when I run "graphql-codegen --config codegen.yml" via npm I get this error:

"Error: Query root type must be provided"

The server side is .Net Core implementation using GraphQL ASPNetCore. I have 4 different queries defined and each one works via graphiql.

Any ideas on why query root type is now being returned as null?

like image 749
Tom Schreck Avatar asked Jan 06 '20 08:01

Tom Schreck


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 .

What is query type in GraphQL?

A GraphQL query is used to read or fetch values while a mutation is used to write or post values. In either case, the operation is a simple string that a GraphQL server can parse and respond to with data in a specific format. The popular response format that is usually used for mobile and web applications is JSON.

What is the return type of GraphQL?

GraphQL schema says that this object should return 4 properties: id , date , specialist , client .

What is ID type in GraphQL?

ID : The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache. The ID type is serialized in the same way as a String; however, defining it as an ID signifies that it is not intended to be human‐readable.


2 Answers

GraphQL must have at least one @Query() to be considered valid. So maybe only need add any Query to your Resolver code will be helpful. Ex:

export class FooResolver {

  @Query(() => String)
  sayHello(): string {
    return 'Hello World!';
  }
}
like image 166
Dung Le Avatar answered Oct 20 '22 12:10

Dung Le


This error throws when your schema stiching/definitions are incorrect. Please check the check your root schema definitions

https://www.advancedgraphql.com/content/schema-stitching

like image 36
Rigin Oommen Avatar answered Oct 20 '22 13:10

Rigin Oommen