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.

[3.0] TypePolicy Does Not Trigger Network Fetch on Cache Miss

See original GitHub issue

This is a follow up from resolved issue #5709

Summary When using a TypePolicy in a “cache-redirect” style (see code below), and a cache-miss occurs, the query should then generate a network request to get the data (per this thread). In actual fact, the request just returns with an empty object.

Setup

  • A TypePolicy references UserListView from a UserDetailView Query (per below)
  • Initiate a request for a User_by_pk with a ‘cache-first’ fetch policy
    export const UserTypePolicy: TypePolicies = {
        Query: {
          fields: {
            User_by_pk:{
              keyArgs: ["id"],
              read(existingData, { args, toReference }) {
                return existingData || toReference({ __typename: 'User', id: args!.id });
              },
            }
          },
        },
      };

Intended outcome: If “User” entities are not available in cache, a network request should be initiated to get the data

Actual outcome: An empty result is returned, and not network request is generated

How to reproduce the issue:

  1. Setup TypePolicy per above
  2. Initiate a DetailView Query before a ListView query
  3. See that a network request is not triggered, and an empty result is returned

Versions System: OS: macOS 10.15.2 Binaries: Node: 13.6.0 - /usr/local/bin/node Yarn: 1.21.1 - /usr/local/bin/yarn npm: 6.13.4 - /usr/local/bin/npm Browsers: Chrome: 79.0.3945.117 Safari: 13.0.4 npmPackages: @apollo/client: link:…/…/webclient/node_modules/@apollo/client => 3.0.0-beta.23 @apollo/react-hooks: link:…/…/webclient/node_modules/@apollo/react-hooks => 3.2.0-beta.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jamshallycommented, Jan 28, 2020

@benjamn - I have just verified that this issue is resolved as of @apollo/client@3.0.0-beta.26. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced topics on caching in Apollo Client
If the detail view's query fetches any Book field that the list view's query didn't, Apollo Client considers the cache hit to be...
Read more >
Update the apollo cache without calling the graphql server ...
If either cache.writeQuery or your typePolicies merge causes an active query field to be missing from the cache, it will result in a...
Read more >
Pitfalls I fell into during Apollo Client 3.0 migration
Paging not working(an issue with fetchPolicy). fetchPolicy caused an issue with paging when used in conjunction with network-only or network-and-cache .
Read more >
Cache (computing) - Wikipedia
In computing, a cache is a hardware or software component that stores data so that future requests for that data can be served...
Read more >
Advanced Topics on Caching – Angular
If the specific detail query fetches a field that the list query doesn't return, Apollo Client will consider the cache hit to be...
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