typePolicies exisitngData arg is incorrect or missused
See original GitHub issueBased on the example in point 3 here, to replace the cache redirect in apollo-client v3 we need go from this
const cache = new InMemoryCache({
cacheRedirects: {
Query: {
book: (_, args, { getCacheKey }) =>
getCacheKey({ __typename: 'Book', id: args.id })
},
},
});
to this
const cache = new InMemoryCache({
typePolicies: {
Query: {
fields: {
book(existingData, { args, toReference }) {
return existingData ||
toReference({ __typename: 'Book', id: args.id });
}
}
},
},
});
But I’m not sure that’s correct.
If I load a list of books, and then I go to book with id 1, the first time existingData will be undefined
.
Now if I try to load book with id 2, existing data has {__ref: "books:1"}
not undefined, so it will load the incorrect book.
What is the purpose of the existingData arg?
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (8 by maintainers)
Top Results From Across the Web
Customizing the behavior of cached fields - Apollo GraphQL
An array of key arguments that help the cache avoid storing unnecessary duplicate data. You provide field policies to the constructor of InMemoryCache...
Read more >ForgeRock Access Management 6.5 > OAuth 2.0 Guide
Guide showing you how to use OAuth 2.0 with ForgeRock® Access Management (AM). ForgeRock Access Management provides intelligent authentication, ...
Read more >Data not merging, Apollo 3 pagination with field policies
I got this information through apollo chrome plugin. I am using the contenful graphql API: Here is my resource collection args and fields:...
Read more >Sexual Assault - Department of Defense
harassment data were not available for men in 2006. ... 4.3 a Implement the No Wrong Door approach to sexual harassment, sexual assault,...
Read more >Remittances and Development - OECD
The World Bank does not guarantee the accuracy of the data included in this work. The ... Indeed, the risk of misuse of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Glad to hear it’s working @tafelito! This is great feedback - I think we should consider changing
@apollo/client
to be a peer dep in the@apollo/link-X
packages, instead of a dep. I’ve made a note - thanks!No longer an issue - thanks!