I came to know about angular graphql code generator from here. I am trying to use it in my project to generate the graphql types and Query
services for angular.
My codegen.yml file looks like below.
overwrite: true
schema: "http://localhost:9010/myGraphQL"
documents: "apps/myGraphQLApp/src/gqls/**/*.graphql"
generates:
apps/myGraphQLApp/src/app/generated/graphql.ts:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-apollo-angular"
I have a graphql file apps\myGraphQLApp\src\gqls\myBooks.graphql
with following content
query GetMyBooks {
books{
id
name
}
}
I am running npx graphql-codegen --config codegen.yml
, and it fails with following error.
√ Parse configuration
> Generate outputs
> Generate apps/myGraphQLApp/src/app/generated/graphql.ts
√ Load GraphQL schemas
√ Load GraphQL documents
× Generate
→ Query root type must be provided.
Found 1 error
× apps/myGraphQLApp/src/app/generated/graphql.ts
Error: Query root type must be provided.
at assertValidSchema (....\node_modules\graphql\type\validate.js:71:11)
...
My graphql server definitely exposes a query root, and I can invoke it with different clients.
schema {
query: MyGraphQLQueryType
}
I am not sure what I am doing wrong. Any help will be appreciated.