Mocking a GraphQL API
Right-click a folder ▸ Add ▸ GraphQL server.
Configuring
Section titled “Configuring”| Field | Role |
|---|---|
| Schema | The type definitions, in SDL |
| Mock resolvers | A JSON object whose keys are of the form Type.field, for example Query.pets |
| Resolver script | JavaScript receiving (parent, args, context) |
The script wins over the canned values when it is filled in: that is what lets you vary the response according to the arguments received.

Canned values
Section titled “Canned values”The quickest route: the schema describes the shape, the resolvers give the content.
type Animal { id: ID!, nom: String!, espece: String! }type Query { animaux: [Animal!]! }{ "Query.animaux": [ { "id": "1", "nom": "Mistigri", "espece": "chat" }, { "id": "2", "nom": "Rex", "espece": "chien" } ]}Resolver script
Section titled “Resolver script”For when the response has to depend on the input:
// (parent, args, context)if (args.espece) { return animaux.filter((a) => a.espece === args.espece);}return animaux;Subscriptions
Section titled “Subscriptions”The subscriptions declared in the schema are served too: a client can connect to them and receive the messages emitted.
In a scenario
Section titled “In a scenario”The GraphQL server and GraphQL server close actions host the service for the duration of the scenario. See Hosted servers.
What it is for
Section titled “What it is for”Developing a front end before the back end exists, reproducing an error response that is hard to provoke in staging, or freezing a data set for a deterministic test — without depending on a remote service.