MockEnvironment.getMostRecentOperation() does not match the request
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Hi there,
recently I encountered a problem when writing test with `getMostRecentOperation`
I have these argument on the Query that has this arguments
```
$id: ID!
$expandedRowIds: [ID!]
$collapsedRowIds: [ID!]
```
Since the last 2 parameters are optional, when I use loadQuery, I do not pass anything when they are not needed.
Everything works fine when I run the app, but when I try to write tests and mock the response in getMostRecentOperation, I get the following error:
`"MockEnvironment: Cannot respond to request, it has not been requested yet."`
I was digging around and found out that the problem is caused by the following comparison in the `getRequests(input)` method.
```
if (operationDescriptor) {
// If we handling `OperationDescriptor` we also need to check variables
// and return only pending request with equal variables
return areEqual(operationDescriptor.request.variables, pending.variables); <---- This line
} else {
// In the case we received `ConcreteRequest` as input we will return
// all pending request, even if they have different variables
return true;
}
```
When I compare the `operationDescriptor.request.variable` and `pending.variables`
I find this:
```
{ id: "someID", expandedRowIds: null, collapsedRowIds: null}
vs.
{ id: "someID" }
```
To me it seems like these should be considered as same requests, therefore I'd suggest to filter out all null values.
My current workaround was instead of making the variables for the query optional, I had to define them as `Array | null` and pass null explicitly.
(I'd open an MR, but it's hard for me to get the CLA with my current employer)
Contributor guide
Assessment
This issue has not been assessed yet.