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 and merge functions we can see that merge is called first in this case, and it writes null. 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
Issue Description
I have a query with client field:
And
typePolicies:When I do
const {data} = await client.query({query}), I expectdata.child.clientFieldto be1, but it'snullinstead.I assume it may be helpful:
readandmergefunctions we can see thatmergeis called first in this case, and it writesnull. That's the problem.@clientonly 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.gitcd apollo-nested-client-fieldnpm inpm test@apollo/clientversion4.0.5