How to Override GraphQL API Query & Mutations
Abhishek Sachan
July 24, 2024
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 request body can help.
If you need to override the request body for a GraphQL API. For scenarios where you need to switch models or modify fields in a query, use the programmatic option in the request body rule to selectively modify GraphQL requests.
Video Tutorial
Steps to Configure Rule
Follow the below steps to override API Requests.
- Create a new Modify Request Rule.
- Use your API hostname & path as source conditions like –
company.com/api/graphql
- Under Request Body select
Programmatic
- We can filter and modify the request using the below code. Make sure you replace
[modified query]
with your query. - Save the rule and test.
function modifyRequestBody(args) {
const { method, url, body, bodyAsJson } = args;
if(bodyAsJson[0].operationName = 'ListArticles'){
bodyAsJson[0].query = '[modified query]'
}
return body;
}
Further Reading
Subscribe for latest updates
Share this article
Related posts
Top 15 Black Friday Developer Tools & SaaS Deals 2024
Rahul
November 29, 2024
Introducing Requestly Student Program
Empowering students with free tools for API development and debugging. Explore the Requestly Student Program today!
Rahul
November 15, 2024
Top 10 Tools to Speed up Android Development
Dinesh Thakur
November 12, 2024