Mock GraphQL API response
A handy way to mock GraphQL responses is to use the Modify Response rule along with the Request Payload filter.
Currently, it is a common practice to pass operationName for GraphQL queries to differentiate similar queries or for verbose logging on the backend.
The operationName is passed as the Request payload of the HTTP request that is meant to carry the GraphQL query, you can target these requests using the Request Payload filter and alter the data returned.
As you can see, you must make sure that the data that you return has the following structure.
1
{
2
"data": { ... },
3
"errors": [ ... ]
4
}
Copied!
  • data contains the result to be returned for the given query. This is where you can read, alter and replace the response using the Modify Response Rule,
  • errors contains any errors that occurred while fetching the query. This can be used to test the how your site handles errors.
Read the blog post for further explanation.
Copy link