Incorrect handling of null arguments in list literals
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
When a fragment defines and argument with a null default value, and the argument is used in a list literal, in the generated query the list is missing the null element. This seems to cause a cache miss when using `useFragment`.
For example, given the fragment:
```graphql
fragment MyFragment on Foo
@argumentDefinitions(myArgument: { type: "String", defaultValue: null })
{
plainField
anotherField(bar: ["some literal", $myArgument])
}
```
Spread in a query without passing any arguments:
```
query MyQuery {
myFoo {
...MyFragment
}
}
```
The generated query looks like:
```
query MyQuery {
# ...
fragment MyFragment on Foo {
plainField
anotherField(bar: ["some literal"])
}
```
Whereas I would expect `anotherField(bar: ["some literal", null])`.
Then when I try `useFragment`, even if the server does return a value for both `plainField` and `anotherField`, the result only contains data for `plainField`, and claims `anotherField` is `undefined`. The contents of `anotherField` are present in the store as `client:nodeID:myFoo:anotherField(bar:["some literal"])` but I suspect it is being looked up with `bar:["some literal", null]`.
If you have any code pointers I can submit a PR which would change the lookup behavior to match the `null` elements elimination, but I wonder if we should remove the `null` elements elimination entirely.
Contributor guide
Research direction
Reproduce the fragment and query shown in the issue, then inspect the generated query and the store key used by useFragment. The fix is complete when null list elements are handled consistently and useFragment returns anotherField instead of undefined; verify with a focused reproduction or existing test if one can be found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, javascript
- Domain
- frontend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100