TypeScript Mock Builder
Generate typed, faker-powered mock factory functions for every schema type, fragment and operation.
- Package
- graphql-codegen-mock-builder
- Version
- 0.4.1
- Weekly downloads
- 133
- License
- MIT
- Updated
- Jul 22, 2026
Installation
npm i -D graphql-codegen-mock-builder
yarn add -D graphql-codegen-mock-builder
pnpm add -D graphql-codegen-mock-builder
bun add -D graphql-codegen-mock-builder
The plugin emits a factory per object, input, interface and union type. Each factory calls
@faker-js/faker when it runs, so every call returns fresh data, and
overrides is spread last so you can pin any field:
The generated code imports @faker-js/faker (v9 or v10), so install it in your project too.
Usage
Set typesPrefix, typesSuffix, namingConvention and enumStyle: 'ts-enum' to match your
typescript plugin config, so the generated factories type-check against your existing types.
Operations mode
With mode: 'operations', the plugin emits a factory per fragment and operation instead, typed to
the typescript-operations result type and built from the selection set. Add it to a
near-operation-file block so each factory lands next to the type it returns:
See the README for all options, the field-name heuristics and how circular types are handled.