{"id":47850,"library":"graphql-data-generator","title":"graphql-data-generator","description":"GraphQL testing utility for generating mock data objects and operation mocks from your schema, with TypeScript types. Current stable version is 0.4.7, with weekly releases on npm. It combines generated types, patching mechanisms, and customizable transforms for common object variations. Key differentiators: built-in mock coverage assertions, array helpers like `next` and `last`, and a `MockedProvider` wrapper for Apollo Client with better stack traces, making it more comprehensive than simple faker-based mocks. Requires peer dependencies graphql, @graphql-tools/graphql-tag-pluck, react, @types/react, @apollo/client 3, @testing-library/dom, and @testing-library/react.","status":"active","version":"0.4.7","language":"javascript","source_language":"en","source_url":"https://github.com/voces/graphql-data-generator","tags":["javascript","typescript"],"install":[{"cmd":"npm install graphql-data-generator","lang":"bash","label":"npm"},{"cmd":"yarn add graphql-data-generator","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql-data-generator","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for schema parsing and type definitions","package":"graphql","optional":false},{"reason":"Peer dependency for extracting GraphQL operations from source files","package":"@graphql-tools/graphql-tag-pluck","optional":false},{"reason":"Peer dependency for MockedProvider component","package":"react","optional":true},{"reason":"Peer dependency for React type support","package":"@types/react","optional":true},{"reason":"Peer dependency for MockedProvider and GraphQL client mocking","package":"@apollo/client","optional":true},{"reason":"Peer dependency for testing utilities","package":"@testing-library/dom","optional":true},{"reason":"Peer dependency for React testing utilities","package":"@testing-library/react","optional":true}],"imports":[{"note":"init is a named export, not default. Patch is a type for patches.","wrong":"import graphqlDataGenerator from 'graphql-data-generator'","symbol":"init","correct":"import { init, Patch } from 'graphql-data-generator'"},{"note":"graphql-data-generator provides its own MockedProvider wrapping Apollo's with better assertions.","wrong":"import { MockedProvider } from '@apollo/client/testing'","symbol":"MockedProvider","correct":"import { MockedProvider } from 'graphql-data-generator'"},{"note":"ESM-only package; require() will cause an error.","wrong":"const { assertMockCoverage } = require('graphql-data-generator')","symbol":"assertMockCoverage","correct":"import { assertMockCoverage } from 'graphql-data-generator'"}],"quickstart":{"code":"import { readFileSync } from 'node:fs';\nimport { init, Patch } from 'graphql-data-generator';\n\nconst schema = readFileSync('schema.graphql', 'utf-8');\n\nconst build = init<Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>, Record<string, any>>(\n  schema,\n  {},\n  {},\n  {},\n  {},\n  {},\n  {}\n)(() => ({}));\n\nconst user = build.User({ id: '1', name: 'Alice' });\nconsole.log(user);","lang":"typescript","description":"Shows minimal setup to initialize a builder and build a User object with overrides."},"warnings":[{"fix":"Pin to current version and test upgrades thoroughly.","message":"API may change drastically before v1 as project is still experimental","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Install peer deps manually: npm install graphql @graphql-tools/graphql-tag-pluck react @types/react @apollo/client @testing-library/dom @testing-library/react","message":"Peer dependencies are required but not listed as direct dependencies; npm may not install them automatically","severity":"gotcha","affected_versions":">=0.4.0"},{"fix":"Call init as init(...)(() => ({...})) not init(...).","message":"init function uses a curried call pattern — double parentheses — which can be confusing","severity":"gotcha","affected_versions":">=0.4.0"},{"fix":"Always import MockedProvider from 'graphql-data-generator' directly.","message":"The old MockedProvider export path may be removed in future versions","severity":"deprecated","affected_versions":">=0.4.0"}],"env_vars":null,"search_vec":"'/dom':95 '/graphql-tag-pluck':87 '/react':100 '0.4.7':26 '3':91 'apollo':64 'apollo/client':90 'array':53 'assert':52 'base':78 'better':67 'built':48 'built-in':47 'client':65 'combin':33 'common':42 'comprehens':73 'coverag':51 'current':22 'customiz':39 'data':3,11 'depend':82 'differenti':46 'faker':77 'faker-bas':76 'generat':4,9,34 'graphql':2,5,83,85 'graphql-data-gener':1 'graphql-tool':84 'helper':54 'javascript':101 'key':45 'last':58 'librari':94,99 'like':55 'make':70 'mechan':37 'mock':10,15,50,79 'mockedprovid':61 'next':56 'npm':31 'object':12,43 'oper':14 'patch':36 'peer':81 'react':88 'releas':29 'requir':80 'schema':18 'simpl':75 'stabl':23 'stack':68 'test':6,93,98 'testing-librari':92,97 'tool':86 'trace':69 'transform':40 'type':21,35 'types/react':89 'typescript':20,102 'util':7 'variat':44 'version':24 'week':28 'wrapper':62","created_at":"2026-06-07T16:53:38.747467+00:00","updated_at":"2026-06-07T16:53:38.747467+00:00","problems":[{"fix":"Run npm install graphql-data-generator --save-dev and ensure tsconfig.json includes node_modules types.","cause":"Package not installed or missing TypeScript declaration files.","error":"Cannot find module 'graphql-data-generator' or its corresponding type declarations."},{"fix":"Use import { init } from 'graphql-data-generator' instead of import init from 'graphql-data-generator'.","cause":"Importing default export instead of named export init.","error":"TypeError: (0 , graphql_data_generator.init) is not a function"},{"fix":"Ensure you've generated types via CLI and passed correct query/mutation/subscription/type/input objects to init.","cause":"init not called with correct generic types or missing type generation step.","error":"Property 'User' does not exist on type ..."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/voces/graphql-data-generator#readme","github":"https://github.com/voces/graphql-data-generator","docs":null,"changelog":null,"pypi":null,"npm":"graphql-data-generator","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}