How to Override GraphQL API Responses
Abhishek Sachan
July 24, 2024
1MIN READ
Frontend developers often need to test their code with variations in API responses. In this post, learn how to override GraphQL API responses.
Once you understand how to debug and override GraphQL API using Requestly. You might want to explore how you can use Requestly in different scenarios of your development cycle(SDLC). Let’s explore how modifying the response can help.
Frontend developers frequently need to test their code with variations in API responses. To override the response you can use the Modify Response Rule. For example, assume you have a GraphQL query to fetch a list of articles for a blogging website like medium.com. You may need to modify the response of ListArticles GraphQL API to test features like displaying only two categories at a time, and handling large title lengths or small excepts.
Video Tutorial
Steps to Create
Follow the steps below to override the response of this API.
- Start by creating a new Modify API Response Rule.
- Select the Resource Type as GraphQL API.
- Use your API’s hostname and path as source conditions like –
company.com/api/graphql
- Under GraphQL Operations in the Key field, enter the operation name’s path, such as
0.operationName
. ChooseEquals
for exact matches orContains
for broader searches. Enter the operation name in the value field. You can also target other parts of the request body(JSON-based). - In the status code select the status codes like 4xx, 5xx, etc.
- In Response Body, you can select from Static or Dynamic response body as per your requirement.
- Save the Rule & Test.
Further Reading
Abhishek Sachan
Abhishek is Growth Engineer at Requestly and has profound love for programming.
Contents​
Subscribe for latest updates​
Share this article
Related posts
Our journey to finding Product-Market Fit
Sachin Jain
December 5, 2024
How Blockthrough uses Requestly to seamlessly test their JS on publisher websites
Sagar Soni
December 4, 2024
The Best Open Source API Mocking Tool for developers (With examples)
Anmol Baranwal
December 2, 2024