{"id":26491413,"url":"https://github.com/dali-benothmen/graphql-fake-data-generator","last_synced_at":"2026-03-02T19:08:20.742Z","repository":{"id":206656801,"uuid":"717386602","full_name":"dali-benothmen/graphql-fake-data-generator","owner":"dali-benothmen","description":"A powerful and flexible tool designed to generate mock data for GraphQL schemas.","archived":false,"fork":false,"pushed_at":"2025-03-15T21:36:37.000Z","size":159,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-15T22:26:22.217Z","etag":null,"topics":["graphql","javascript","mock-data-generator","nodejs","react","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dali-benothmen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-11T10:31:10.000Z","updated_at":"2025-03-15T21:36:42.000Z","dependencies_parsed_at":"2025-03-16T01:01:32.858Z","dependency_job_id":null,"html_url":"https://github.com/dali-benothmen/graphql-fake-data-generator","commit_stats":null,"previous_names":["medali5543/graphql-mock-data-generator","medali5543/graphql-fake-data-generator"],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dali-benothmen%2Fgraphql-fake-data-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dali-benothmen%2Fgraphql-fake-data-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dali-benothmen%2Fgraphql-fake-data-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dali-benothmen%2Fgraphql-fake-data-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dali-benothmen","download_url":"https://codeload.github.com/dali-benothmen/graphql-fake-data-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244581182,"owners_count":20476067,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","javascript","mock-data-generator","nodejs","react","typescript"],"created_at":"2025-03-20T08:37:46.747Z","updated_at":"2026-03-02T19:08:15.710Z","avatar_url":"https://github.com/dali-benothmen.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GraphQL Fake Data Generator\n\n## Description\n\nGraphQL Fake Data Generator is a powerful and flexible tool designed to generate mock data for GraphQL schemas. It provides an easy and efficient way to create realistic and customizable mock data based on your GraphQL schema, which is ideal for testing, development, and demonstration purposes.\n\n## Installation\n\n```bash\nnpm install graphql-fake-data-generator --save-dev\n```\n\n```bash\nyarn add -D graphql-fake-data-generator\n```\n\n```bash\npnpm add -D graphql-fake-data-generator\n```\n\n## Basic Usage\n\n### Create Schema from String\n\nTo create a GraphQL schema from a string:\n\n```js\nconst schemaString = `\n  type Query {\n    users: [User]\n  }\n  type User {\n    id: ID\n    name: String\n  }\n`\n```\n\n### Parse Schema\n\nParse the schema to convert it into a usable format:\n\n```js\nimport { parseGraphQLSchema } from 'graphql-fake-data-generator'\n\nconst parsedSchema = parseGraphQLSchema(schema)\n```\n\n### Analyze Schema\n\nAnalyze the parsed schema to understand its structure:\n\n```js\nimport { analyzeSchema } from 'graphql-fake-data-generator'\n\nconst analyzedSchema = analyzeSchema(parsedSchema)\n```\n\n### Generate Mock Data\n\nGenerate mock data based on the analyzed schema:\n\n```js\nimport { generateMockData } from 'graphql-fake-data-generator'\n\nconst mockData = generateMockData(analyzedSchema)\n```\n\n### Example:\n\n```js\nimport { parseGraphQLSchema, analyzeSchema, generateMockData } from 'graphql-fake-data-generator'\n\nconst schemaString = `\n  type Query {\n    users: [User]\n  }\n  type User {\n    id: ID\n    name: String\n  }\n`\n\nconst parsedSchema = parseGraphQLSchema(schema)\nconst analyzedSchema = analyzeSchema(parsedSchema)\nconst mockData = generateMockData(analyzedSchema)\n```\n\n### Result:\n\n```js\n{\n  users: [\n    {\n       id\": \"14c56ec5-1f79-4d9e-aab9-759ba6dcc950\",\n       name\": \"terra\",\n       email\": \"conscendo\"\n    }\n  ]\n}\n```\n\n## Load Schema from File\n\nTo load a GraphQL schema from a file:\n\n```js\nimport { readFileSync } from 'fs'\nimport { parseGraphQLSchema, analyzeSchema, generateMockData } from 'graphql-fake-data-generator'\n\n// Method 1: Read existing GraphQL schema file and convert it into string.\nconst schemaString = readFileSync('path/to/your/schema.graphql', 'utf-8')\nconst parsedSchema = parseGraphQLSchema(schemaString)\n\n// Method 2: Pass the GraphQL schema file path directly to the parseGraphQLSchema function.\nconst parsedSchema = parseGraphQLSchema('./schema.graphql')\nconst analyzedSchema = analyzeSchema(parsedSchema)\nconst mockData = generateMockData(analyzedSchema)\n```\n\n## Generate Mock Data with Options\n\n### Customizing List Length\n\nSpecify the length of lists in the generated mock data:\n\n```js\nconst mockDataWithListLength = generateMockData(analyzedSchema, {\n  listLength: 10, // Specifies the number of items in list fields\n})\n```\n\nNB: Please be aware that if your schema does not return an array, the 'listLength' parameter will be unavailable. Including it in the options will result in an error.\n\n### Customizing Data\n\nProvide custom data generators for specific fields:\nIf the default data generated appears unrealistic, you have the option to customize the output for specific fields\n\n```js\nimport { faker } from 'faker-js/faker'\n\nconst mockDataWithCustomData = generateMockData(analyzedSchema, {\n  query: {\n    name: () =\u003e faker.person.fullName(),\n    email: () =\u003e faker.internet.email(),\n  },\n})\n```\n\nIn the example above, the `name` and `email` fields of the `users` query will use the provided custom generator functions. This allows for specific customization of the mock data returned for these fields.\n\n### Output\n\n```js\n{\n  users: [\n    {\n      id=: \"14c56ec5-1f79-4d9e-aab9-759ba6dcc950\",\n      name: \"Claude Hyatt\",\n      email: \"Janessa23@hotmail.com\"\n    }\n  ]\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdali-benothmen%2Fgraphql-fake-data-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdali-benothmen%2Fgraphql-fake-data-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdali-benothmen%2Fgraphql-fake-data-generator/lists"}