Skip to main content

Getting Started

Installation

yarn add --dev graphql-codegen-factories

The package is split into two plugins:

  • graphql-codegen-factories/schema: generates factories based on a GraphQL schema.
  • graphql-codegen-factories/operations: generates factories based on GraphQL operations. The schema plugin is required for the operations plugin to work as it leverages the factories generated by the former.

Schema

The factories generated by this plugin use the types generated by @graphql-codegen/typescript so make sure it is installed. The next step is to add graphql-codegen-factories/schema to the list of plugins in your codegen.yml configuration file.

codegen.yml
overwrite: true
schema: ./schema.graphql
documents: ./**/*.graphql
generates:
./types.ts:
plugins:
- typescript
- graphql-codegen-factories/schema

To access the full list of options, see the documentation for the configuration.

Operations

The factories generated by this plugin use the types generated by @graphql-codegen/typescript-operations so make sure it is installed. It also leverages the factories generated by the schema plugin which must be installed as described above. The next step is to add graphql-codegen-factories/operations to the list of plugins in your codegen.yml configuration file along with the path to the file with the factories.

codegen.yml
overwrite: true
schema: ./schema.graphql
documents: ./**/*.graphql
generates:
./types.ts:
plugins:
- typescript
- graphql-codegen-factories/schema
- typescript-operations
- graphql-codegen-factories/operations

To access the full list of options, see the documentation for the configuration.