CLI
Install the apollo-mock binary for your platform with:
curl -fsSL https://raw.githubusercontent.com/apollographql/apollo-mock/main/install.sh | sh1. Generate fake data
--graphql-dir points at a directory containing .graphql/.graphqls files: exactly one of them
must be the schema (the file containing at least one type system definition, e.g. type/enum/
directive), the rest are treated as operation files (see Mocking operations
below). sample/graphql has an example of both.
ollama pull llama3.2apollo-mock generate --graphql-dir sample/graphql --output-dir data --provider ollamaUse --model to pick another model and --base-url for a non-default Ollama endpoint.
Alternatively, use the Anthropic API with --provider anthropic:
export ANTHROPIC_API_KEY=sk-ant-...apollo-mock generate --graphql-dir sample/graphql --output-dir data --provider anthropicThe API key can also be passed with --api-key instead of the ANTHROPIC_API_KEY environment variable.
Use --model to pick another Claude model (default: claude-haiku-4-5).
Or use the Vercel AI Gateway with --provider vercel, which can
route to any model it supports using a creator/model name (e.g. openai/gpt-5-mini):
export AI_GATEWAY_API_KEY=...apollo-mock generate --graphql-dir sample/graphql --output-dir data --provider vercelThe API key can also be passed with --gateway-api-key instead of the AI_GATEWAY_API_KEY environment
variable. Use --model to pick another model (default: anthropic/claude-haiku-4.5) and --base-url
for a non-default gateway endpoint.
For testing, --provider random fills the schema with random data (lorem ipsum text, random
enum/number/boolean values) without calling any LLM:
apollo-mock generate --graphql-dir sample/graphql --output-dir data --provider randomThis writes, under data/:
entity/<TypeName>/<id>.json: one file per schema-based fake entity. Scalar and enum fields are filled by the LLM; fields pointing to other types are linked with{__typename, id}references that the server hydrates at execution time. Regenerating with the same--output-dirkeeps existing entities stable across schema changes: fields removed from the schema are dropped, only newly added fields are asked from the LLM, andids never change.operation/<operationName>.json: one file per named operation using the@mockdirective (see below), mapping the GraphQL path in the document to the mocked value.
Mocking operations
Besides schema-based entities, individual operations can be mocked with the @mock directive:
directive @mock(hint: String, value: Any) on QUERY | MUTATION | SUBSCRIPTION | FIELD@mock(value: ...)uses the given GraphQL literal verbatim.@mock(hint: "...")passes the hint to the data provider, which generates a value matching the field’s (or, at the operation root, the whole selection set’s) shape.
query GetProducts { products { name price @mock(value: 9.99) category @mock(hint: "a category for kitchen appliances") { name } }}writes operation/GetProducts.json as {"products.price": 9.99, "products.category": {"name": "..."}}.
A @mock directive on the operation itself (as opposed to a field) mocks the whole response, stored
under the empty-string path.
2. Serve the fake data
apollo-mock serve --schema sample/graphql/schema.graphqls --data dataThen:
- GraphQL endpoint: http://localhost:4000/graphql
- Sandbox: http://localhost:4000/
curl -s http://localhost:4000/graphql \ -H "Content-Type: application/json" \ -d '{"query": "{ products { name price category { name } reviews { rating author } } }"}'Pass --port 0 to have the OS pick a free port automatically.