Unable to modify GraphQL API response on LeetCode site

I am trying to modify the response of graphQL API on leetcode. Here is the API URL - leetcode.com/graphql and just to try I wanted to make the categories set to empty array when the operationName is “GetCategories”

I have already gone through - Mocking graphQL APIs response and followed it but still this is not working for me.

Here is the code that I am trying to make work

function modifyResponse(args) {
  const {method, url, response, responseType, requestHeaders, requestData, responseJSON} = args;
  // Change response below depending upon request attributes received in args

  const newResponse = JSON.parse(response);
  newResponse.data.categories = [];
  return newResponse;
}

Is there anything that I am doing wrong?

1 Like

@Sachin I checked. The response is a blob in this case and reading JSON from blob would be an asynchronous job.

const responseText = await response.text(); //async
const newResponse = JSON.parse(responseText);
newResponse.data.categories = [];
const newResponseText = JSON.stringify(newResponse);

return new Blob([newResponseText], { type: "application/json;charset=utf-8" });

Requestly currently does not support asynchronous override of response when XMLHttpRequest API is used. It could have worked if fetch API was used to make the request.

However, Requestly Desktop App provides more flexibility with different kind of requests. It may be worth to try it out once.

2 Likes

@Vaibhav_Nigam Is it possible to support this for XHR requests at all or not? Will this be possible with MV3 if not with MV2 implementation?