Im having an issue with tracking to mock a graphql call. So everything is working in postman, like I have the mock server running, the request, the example request, and if I use the Code -> curl I can copy that and paste into the console and it returns the correct data from the mock. Im using the "x-mock-match-request-body": "true" header.
But when I try to use it in an app Im building (flutter), it can’t find the request and I get
Network Error: 404 {"error":{"name":"mockRequestNotFoundError","message":"Double check your method and the request path and try again.","header":"No matching requests"}}
I checked the strings of the query and they both looks the same, same params, same number of spaces, etc. So Im wondering how the match algorithm works? Could some special character break the match?
In addition to the GraphQL query, make sure that your GraphQL variables are also the same. Note: There’s a difference in the matching algorithm between not listing any variables at all vs having "variables":{} in the request body. I believe Postman defaults to the latter. Check your example to see what’s there.
Hey @kevin.swiber thanks for replying me back. I have checked and everything seems to be exactly the same, but for some reason it is not matching. The only difference I see is the “operationName” is not listed in the query that matches. But it’s part of the query.
Here you can see both requests the one that matches, using curl, and the one that don’t using flutter.
In the meantime, one workaround is to use a different request body style in the example editor. Right now, your example request body probably looks something like this with GraphQL selected:
If you select raw and type in the request body in JSON-style, you can add in operationName. This should match on your mock request. It should look something like this:
Kevin, thanks again! I did try to do that, now the body is exactly the same as the request but it is still failing, it’s like it tries to also match all the headers, which makes sense, but do you know how that works? like if in my example I have defined onlyContent-Type: application/json will it check if that key is present and won’t care about all the others or does that mean that that key should be the only present header?
Request headers should only be checked for matching when x-mock-match-request-headers is set and includes a whitelisted set of headers upon which to check. See the docs here:
Mock requests also accepts optional headers x-mock-match-request-body for request body matching and x-mock-match-request-headers for matching incoming mock request headers. You must set x-mock-match-request-body header to true to enable request body matching. To enable incoming mock request headers matching, you must ensure that x-mock-match-request-headers header is present in the request and its value is a comma separated string of header keys that you want to match against in the saved examples.