question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

typePolicies exisitngData arg is incorrect or missused

See original GitHub issue

Based 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:closed
  • Created 4 years ago
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
hwillsoncommented, Jan 31, 2020

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!

0reactions
hwillsoncommented, Jun 12, 2020

No longer an issue - thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found