Getting Started
Getting Started
Installation
Installation
HTTP Rules (Modify Traffic)
HTTP Rules (Modify Traffic)
Overview
Redirect URL (Map Local, Map Remote)
Replace Strings (Switch Hosts, API Endpoints)
Modify Headers
Modify Request Body
Modify Response Body
Modify Query Params
Modify Cookies
Modify DOM/Inject scripts
Modify User Agents
Delay Request
Cancel Rule
Organizing Rule
Import/Export Rules from File
Pause/Resume Requestly
Rule Operators
Advance Targeting
Sharing Rules
Map Local
Map Remote
Pinning Rules
GraphQL Support
Edit and Replay
Import Setting from Charles Proxy
Test URL Condition
Test this Rule
File Server
File Server
Sessions Replay
Sessions Replay
Getting Started
Getting Started
Installation
Installation
HTTP Rules (Modify Traffic)
HTTP Rules (Modify Traffic)
Overview
Redirect URL (Map Local, Map Remote)
Replace Strings (Switch Hosts, API Endpoints)
Modify Headers
Modify Request Body
Modify Response Body
Modify Query Params
Modify Cookies
Modify DOM/Inject scripts
Modify User Agents
Delay Request
Cancel Rule
Organizing Rule
Import/Export Rules from File
Pause/Resume Requestly
Rule Operators
Advance Targeting
Sharing Rules
Map Local
Map Remote
Pinning Rules
GraphQL Support
Edit and Replay
Import Setting from Charles Proxy
Test URL Condition
Test this Rule
File Server
File Server
Â
GraphQL Support
This page explains how you can alter GraphQL API requests and responses using Requestly.
Modifying GraphQL responses
In GraphQL, there is typically just one HTTP endpoint for all client interactions. And to specify which operation to execute, it is a common practice to passÂ
operationName
 in the request payload.For example,
POST /graphql { "operationName": "getUsers", "query": ` query getUsers { users { id email } } ` }
To modify response of a GraphQL request, you may create a Modify API Response rule and target
operationName
 field in the request payload.Select Resource Type as
GraphQL API
and in GraphQL Operation (Request Payload Filter)
, enter:- Key as
operationName
- value as
getUsers
Note:
Key
is the JSON key in the request payload.
It also supports nested path. For instance, if operation name is available at path data.operationName
instead of root, Key can be specified as data.operationName
.Â
If your GraphQL request does not specify
operationName
, you should select Resource Type as REST API
and use Dynamic (JavaScript)
mode to filter the request and override the response. For example, in the below GraphQL request, there is no
operationName
field. The operation getUsers
is instead specified in query
field.POST /graphql { "query": ` query getUsers { users { id email } } ` }
The JavaScript code would look like:
function modifyResponse(args) { const {url, response, requestData, responseJSON} = args; if (requestData.query?.includes("query getUsers")) { // return custom response from this query console.log("Requestly: Modifying response", { query: requestData.query }); return {...responseJSON, custom: true}; } // return original response return response; }
Â
Modifying GraphQL requests
If you have a use-case to modify the GraphQL query or variables, you may create a Modify Request Body rule where the request body can be altered.
Â
Â
Â