Skip to main content

All Plugins

The general purpose of GraphQL Code Generator is to parse GraphQL syntax, transform it into an AST and then output it into desired formats which can vary. Since there can potentially be an infinite number of formats, we can't predict them all. However, some formats are more likely to be used, thus, we've prepared pre-defined code generation plugins which are built for these formats.

Available Plugins#

Below is a table that lists all available plugins which can be installed via NPM, along with a short description. If you're looking for anything specific, we might already have the solution:

FormatPurposePackage Name & Docs
typescriptGenerate types for TypeScript - those are usually relevant for both client side and server side code@graphql-codegen/typescript
typescript-operationsGenerate client specific TypeScript types (query, mutation, subscription, fragment)@graphql-codegen/typescript-operations
typescript-resolversGenerate TypeScript signature for server-side resolvers@graphql-codegen/typescript-resolvers
typed-document-nodeGenerate typed DocumentNode to by used with supporting libraries@graphql-codegen/typed-document-node
typescript-apollo-client-helpersGenerates helpers for better integration of Apollo-Client v3 and TypeScript@graphql-codegen/typescript-apollo-client-helpers
typescript-react-queryGenerates ready-to-use React Hooks for react-query library@graphql-codegen/typescript-react-query
typescript-apollo-angularGenerate TypeScript types, and Apollo-Angular Services@graphql-codegen/typescript-apollo-angular
typescript-react-apolloGenerate TypeScript types, and React-Apollo Components@graphql-codegen/typescript-react-apollo
typescript-vue-apolloGenerate TypeScript types, and Vue Apollo composition functions@graphql-codegen/typescript-vue-apollo
typescript-urqlGenerate TypeScript types, and Urql Components@graphql-codegen/typescript-urql
typescript-graphql-requestGenerates fully-typed ready-to-use SDK for graphql-request@graphql-codegen/typescript-graphql-request
typescript-generic-sdkGenerates fully-typed generic SDK you can hook into any client.@graphql-codegen/typescript-generic-sdk
typescript-stencil-apolloGenerate TypeScript types, and Stencil Apollo Components@graphql-codegen/typescript-stencil-apollo
typescript-mongodbGenerate server-side TypeScript types, with MongoDB models@graphql-codegen/typescript-mongodb
typescript-graphql-files-modulesGenerate declare module for .graphql files@graphql-codegen/typescript-graphql-files-modules
typescript-document-nodesGenerate TypeScript source files files that use graphql-tag@graphql-codegen/typescript-document-nodes
typescript-type-graphqlGenerate TypeScript types compatible with TypeGraphQL@graphql-codegen/typescript-type-graphql
typescript-oclifGenerate commands for oclif command line interfaces@graphql-codegen/typescript-oclif
addAdd any string that you wish to the output file@graphql-codegen/add
schema-astPrints the merged schemas as AST@graphql-codegen/schema-ast
fragment-matcherGenerates an introspection result with only Unions and Interfaces@graphql-codegen/fragment-matcher
named-operations-objectGenerates a type-safe list of all your available GraphQL operations and fragments@graphql-codegen/named-operations-object
introspectionGenerates an introspection result@graphql-codegen/introspection
timeAdd the generation time to the output file@graphql-codegen/time
flowGenerate types for Flow type based on your GraphQL schema@graphql-codegen/flow
flow-resolversGenerate resolvers signature for Flow@graphql-codegen/flow-resolvers
flow-operationsGenerate types for Flow type based on your GraphQL operations@graphql-codegen/flow-operations
reason-clientGenerate ReasonML types based on your GraphQL schema for use in a client application@graphql-codegen/reason-client
kotlingenerates Kotlin backend classes for Enums and Input types@graphql-codegen/kotlin
javagenerates Java backend classes for Enums and Input types@graphql-codegen/java
java-resolversgenerates Java backend resolvers signature@graphql-codegen/java-resolvers
java-apollo-androidgenerates Apollo Android parsers and mappers@graphql-codegen/java-apollo-android
Scala Pluginsgenerates types for schema and operations, maintained by aappddeevv@aappddeevvv/graphql-code-scala-operations,@aappddeevvv/graphql-code-scala-schema
apollo-typed-documentsGenerates declare module for .graphql files with generic TypedDocumentNode<TVariables, TData>. Also generates helper function to create mocks for Apollo Client MockedProvider. Maintained by rubengrillapollo-typed-documents/lib/codegenTypedDocuments,apollo-typed-documents/lib/codegenApolloMock
@homebound/graphql-typescript-factoriesGenerates factory methods for use in client-side GraphQL tests that are stubbing/mocking out GraphQL responses.homebound-team/graphql-typescript-factories
@homebound/graphql-typescript-simple-resolversgenerates types for implementing an Apollo-/graphql-style implementation in TypeScript.homebound-team/graphql-typescript-simple-resolvers
@homebound/graphql-typescript-resolver-scaffoldingThe generated scaffolds are extremely simple, and really just placeholders for your business logic and tests.homebound-team/graphql-typescript-resolver-scaffolding

In addition, you can build your own code generating plugins based on your specific needs. For more information, check this doc page.

How to use Plugins#

To use a plugin, install its package from npm, then add it to your YML config file:

schema: my-schema.graphql
generates:
output.ts:
- plugin-name-here

Configure Plugins#

To pass configuration to a plugin, do the following:

schema: my-schema.graphql
generates:
output.ts:
- plugin-name-here:
configKey: configValue

You can also pass the same configuration value to multiple plugins:

schema: my-schema.graphql
generates:
output.ts:
config:
configKey: configValue
plugins:
- plugin1-name-here
- plugin2-name-here

You can find the supported configuration for each plugin in its page / README file.