Unused optional query variables set to NULL
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
When using a query that allows for optional variables, Relay sets those _unused variables_ to `null`.
EDIT: This occurs both in the test environment via RelayModernMockEnvironment AND in the normal/production `RelayEnvironment` when using something like `usePaginationFragment` and calling `loadNext`. In the second case, `loadNext` will be called with all of the unused variables set to `null`. Some APIs do not allow an explicit `null` value to be passed.
In testing/RelayModernMockEnvironment:
This can cause a mismatch between the variables used in the `loadQuery` or `useLazyloadQuery` call, and what `RelayModernMockEnvironment.js` is receiving in the `op.request.variables`. Therefore, when the `areEqual` function performs its check the test will fail.
This issue is described in a gist here: https://gist.github.com/bartonyoung/356d810edc73e3377ec27b673dadbad2
A (bad IMO) solution is to make the `loadQuery` call with the unused variables explicitly set to `null`, so that it matches what is received in `RelayModernMockEnvironment.js`. However, some APIs (including the one I am using) do not accept explicit `null` values.
A screenshot from `RelayModernMockEnvironment.js` performing its check and ultimately failing:
This problem is described in a another gitHub issue here: https://github.com/facebook/relay/issues/3872
Contributor guide
Assessment
This issue has not been assessed yet.