A GraphQL Codegen plugin that generates TypeScript mock data factories based on your GraphQL schema. Current stable version is 5.1.1, requires Node >=18, graphql >=14.6.0, and TypeScript >=5.0.0. The plugin supports custom scalar mappers (casual or faker), circular relationship termination, enum value transformation, and includes/excludes filters for specific types. It integrates with the GraphQL Code Generator pipeline to produce type-safe, realistic fake data for testing and development. Compared to alternatives like graphql-faker or msw's data generation, this plugin generates compile-time validated mock objects directly from schema types with TypeScript type inference.
npm install graphql-codegen-typescript-mock-dataNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Example GraphQL Codegen configuration using the mock data plugin with custom scalar mapping for DateTime, adding __typename, and generating 2 elements per list.
Upgrade Node to >=18 and TypeScript to >=5.0.0 before upgrading.
Use 'maybeValue' with explicit undefined handling instead.
Set terminateCircularRelationships: true in config to prevent stack overflow.
Set prefix: 'an' explicitly if you need the old behavior.
Run 'yarn add -D graphql-codegen-typescript-mock-data' or 'npm install --save-dev graphql-codegen-typescript-mock-data'.
Use 'import plugin from 'graphql-codegen-typescript-mock-data'' or require it with .default.
Add typesFile: './src/generated/types.ts' (or your types path) to the plugin config.
Add 'type': 'module' to package.json or use 'require('graphql-codegen-typescript-mock-data').default'.