Registry / testing / graphql-faker

graphql-faker

JSON →
library2.0.0jsnpmunverified

GraphQL Faker v2.0.0 is a CLI tool for mocking or extending GraphQL APIs with realistic fake data from faker.js, requiring no coding. It uses custom directives like @fake, @examples, and @listLength in GraphQL SDL to generate data. Supports proxying existing GraphQL APIs (e.g., GitHub, SWAPI) and extending them with mock fields. Ships with an interactive editor integrating GraphiQL. Requires Node >= 18.12.0. Major v2 release dropped support for older Node versions and may have breaking changes. Release cadence is irregular; maintained on GitHub. Key differentiator: no-code faking with rich directive support and proxy capability.

npm install graphql-faker
INSTALL
IMPORT
SIG · GRAPHQL-FAKER
G
graphql-faker
testingjavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

graphql-faker
npx graphql-faker [options] [SDL file]
const faker = require('graphql-faker');
CLI tool, not a library. Run via npx or global install. Programmatic use is not supported in v2.
@fake directive
field: String @fake(type: firstName)
field: String @fake(type: 'firstName')
Directive arguments are enum-like strings without quotes. Also supports @examples(values: [...]) and @listLength(min:, max:).
Extend mode
graphql-faker ./schema.graphql --extend https://example.com/graphql
graphql-faker --extend https://example.com/graphql ./schema.graphql
SDL file must come before --extend. Order matters.

Creates an SDL file with directives and starts the faker server with interactive editor.

npm install -g graphql-faker echo 'type User { id: ID! @fake(type: uuid) name: String @fake(type: firstName) email: String @fake(type: email) createdAt: String @fake(type: pastDate) posts: [Post] @listLength(min: 1, max: 5) } type Post { title: String @fake(type: lorem) body: String @fake(type: lorem,maxSentences: 3) tags: [String] @examples(values: ["javascript","graphql","faker"]) author: User } type Query { user(id: ID!): User users(limit: Int = 10): [User] }' > schema.graphql graphql-faker ./schema.graphql --open
Debug
Known issues
breakingGraphQL Faker v2 requires Node.js >= 18.12.0. Older versions will fail to install or run.
fix
Upgrade Node.js to version 18.12.0 or later.
affects: <2.0.0
deprecatedThe old faker.js (Marak) is replaced by @faker-js/faker in v2. Some fake types may have changed.
fix
Refer to @faker-js/faker documentation for @fake type names (e.g., 'firstName' is now 'person.firstName' in newer versions).
affects: >=2.0.0
gotchaExtensions with --extend may fail if the proxied GraphQL endpoint requires authentication but headers are not provided.
fix
Use --header or --forward-headers to pass authentication tokens.
affects: >=1.0.0
gotchaThe --open flag opens a browser; on headless servers (e.g., Docker), this will fail unless a display is configured.
fix
Omit --open in headless environments or use Docker with DISPLAY configured.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'graphql-faker'
GraphQL Faker is a global CLI tool, not installed as a local dependency.
fix
Run: npm install -g graphql-faker
Error: Failed to load schema from ./schema.graphql. Syntax Error: Expected Name, found String
The @fake(type: ...) argument should be an unquoted enum value, not a string literal.
fix
Use @fake(type: firstName) instead of @fake(type: 'firstName')
Error: Port 9002 is already in use
Default port is occupied by another process.
fix
Use --port to specify a different port, e.g., graphql-faker --port 3000
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
graphqlrequiredCore dependency for parsing and executing GraphQL schemas
@faker-js/fakerrequiredGenerates fake data values for @fake directive
expressrequiredHTTP server for serving the mock API and editor
Agent activity
6 hits · last 30 days
node
6
Resources