How to configure cache for Viewer Type in 3.0?
See original GitHub issueAs of 3.0, the Viewer
type in our schema throws the Cache data may be lost...
warning in the console because it does not have an id
field, And I’m just not sure the best way to address it. I’m trying to determine the ideal solution here (other than removing the viewer type entirely).
If I write a custom merge function on Viewer
it would need need to be written for each field individually, which seems like a bad idea.
I tried writing a custom merge on Query
but that didn’t seem to work:
new InMemoryCache({
typePolicies: {
Query: {
fields: {
viewer: {
merge(existing, incoming) {
return { ...existing, ...incoming };
},
},
},
},
},
});
If I utilize possibleTypes
and map Viewer
to the types of its fields (eg User
Product
AccountType
), it doesn’t seem to fix the issue. Do I need to remove references to the viewer
in my queries to allow this to work?
The only other option I can think of is adding id
to Viewer
, but trying to avoid that if I can.
Any input is appreciated!
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Ok, since it sounds like
Viewer
is a singleton, you can give it a constant ID (without having to invent a real identity):Alternatively, the following tweak to the
merge
function might make a difference, since it will do a better job of merging sub-fields that have their ownmerge
functions:I’ll leave this issue open in case those solutions don’t work, or you have any other questions.
It doesn’t sound like there is an outstanding issue here, so closing. Thanks!