Integrate With GraphQL Code Generator
GraphQL Modules comes with a built-in support for GraphQL Code Generator
#
Installing DependenciesTo get started, add @graphql-codegen/cli
and necessary templates to your app:
And create schema.ts
to expose the schema of your GraphQL Modules application.
GraphQL Modules won't load any other things such as injectors, resolvers and providers when you just try to get type definitions from your top module, because GraphQL Modules loads every part of module lazily.
#
Exposing Schema to GraphQL Code Generator- Create
src/schema.ts
to expose your type definitions to GraphQL Code Generator without any business logic.
src/schema.ts
#
Creating Configuration for GraphQL Code GeneratorThen create codegen.yml
on your project root.
In the example below, TypeScript files are emitted.
Check the GraphQL Code Generator website for more details.
codegen.yml
You can add a script to package.json
.
#
Using Generated TypingsThen you can use these generated typings everywhere in your project;
The article Writing Strict-Typed GraphQL TypeScript project w/ GraphQL Modules and GraphQL Code Generator explains why you would need this integration.