-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
Description
Issue Description
I have a query with client field:
query {
child {
clientField @client
normalField
}
}
And typePolicies
:
typePolicies: {
Child: {
fields: {
clientField: (value = 1) => value,
},
},
},
When I do const {data} = await client.query({query})
, I expect data.child.clientField
to be 1
, but it's null
instead.
I assume it may be helpful:
- With separated
read
andmerge
functions we can see thatmerge
is called first in this case, and it writesnull
. That's the problem. - With root fields instead of nested ones, it works properly.
- With
@client
only fields it works properly too.
Link to Reproduction
https://github.com/broyde/apollo-nested-client-field
Reproduction Steps
I've created simple jest tests to show the problem.
git clone https://github.com/broyde/apollo-nested-client-field.git
cd apollo-nested-client-field
npm i
npm test
- See the test nested-client-field.test.js and how it fails:
FAIL ./nested-client-field.test.js
● Console
console.log
merge { cachedValue: undefined, value: null }
console.log
read null
● Should resolve nested @client fields properly
expect(received).toEqual(expected) // deep equality
- Expected - 1
+ Received + 1
Object {
"__typename": "Child",
- "clientField": 1,
+ "clientField": null,
"normalField": 2,
}
49 |
50 | const {data} = await client.query({query});
> 51 | expect(data.child).toEqual({
| ^
52 | __typename: 'Child',
53 | clientField: 1,
54 | normalField: 2,
at Object.toEqual (nested-client-field.test.js:51:22)
@apollo/client
version
4.0.5
MaxBag, greenvalera, vanula, dbtnuser, Talktetive and 1 more