[3.0] TypePolicy Does Not Trigger Network Fetch on Cache Miss
See original GitHub issueThis 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:
- Setup TypePolicy per above
- Initiate a DetailView Query before a ListView query
- 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:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@benjamn - I have just verified that this issue is resolved as of @apollo/client@3.0.0-beta.26. Thanks!
Here’s a branch where I’ve added a
Query.person(id)
field: https://github.com/apollographql/react-apollo-error-template/tree/single-person-field-exampleAnd here’s the relevant commit: https://github.com/apollographql/react-apollo-error-template/commit/22dc84616c9e98c1249939814805f782f6afcc8b