MockEnvironment not working as expected with default value in GraphQL query.
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I've recently found an issue while testing one of my component using `useQueryLoader`.
My query contains an optional `countEach` param that has a default value `= 10`.
In my code, I'm calling the searchCallback without passing `countEach`, so in the MockEnvironment, my variables query doesn't have the variable `countEach`. However, the variables from the operationDescriptor query contains that `countEach` param, so the comparison on that [line](https://github.com/facebook/relay/blob/de07cb9f1104bc9bd4365dc979d58b7974a10361/packages/relay-test-utils/RelayModernMockEnvironment.js#L305) returns false, so the query is not retrieved and the mock fails.
The quick solution is to pass the variable to my searchCallback variables, but then I no longer benefit of the default value set on the param. Is there any other solution I am missing? Maybe at the resolver level. Otherwise I believe it may be an issue in the MockEnvironment.
Thanks in advance for any help.
Contributor guide
Research direction
Start in packages/relay-test-utils/RelayModernMockEnvironment.js at the comparison around line 305, and reproduce the issue with useQueryLoader and a GraphQL variable declared with a default value. Verify that the mock lookup handles an omitted countEach variable consistently with the operation descriptor, and confirm the described query can be retrieved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, javascript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100