cache.invalidate causes breakage in simplePagination
Describe the bug
https://github.com/urql-graphql/urql/blob/main/exchanges/graphcache/src/extras/simplePagination.ts#L100C1-L100C26
Is there a reason this line explicitly avoids checking for undefined? On graphcache update resolver cache.invalidate seems to make links undefined which breaks in the .length check...
Can provide a reproduction if this doesn't sound like what should be happening (or if I'm doing something blatantly incorrect).
Reproduction
see description first please
Urql version
@urql/exchange-graphcache 6.3.3 @urql/exchange-persisted 4.1.0 @urql/exchange-request-policy 1.0.2 @urql/exchange-retry 1.2.0 @urql/vue 1.1.2
Validations
- [X] I can confirm that this is a bug report, and not a feature request, RFC, question, or discussion, for which GitHub Discussions should be used
- [X] Read the docs.
- [X] Follow our Code of Conduct
would work right if one of those = was removed
I've been trying to reproduce this but couldn't make it work with the following test
it('works with invalidation', () => {
const Pagination = gql`
query ($skip: Number, $limit: Number) {
__typename
persons(skip: $skip, limit: $limit) {
__typename
id
name
}
}
`;
const store = new Store({
resolvers: {
Query: {
persons: simplePagination(),
},
},
});
const pageOne = {
__typename: 'Query',
persons: [
{ id: 1, name: 'Jovi', __typename: 'Person' },
{ id: 2, name: 'Phil', __typename: 'Person' },
{ id: 3, name: 'Andy', __typename: 'Person' },
],
};
const pageTwo = {
__typename: 'Query',
persons: [
{ id: 4, name: 'Kadi', __typename: 'Person' },
{ id: 5, name: 'Dom', __typename: 'Person' },
{ id: 6, name: 'Sofia', __typename: 'Person' },
],
};
write(
store,
{ query: Pagination, variables: { skip: 0, limit: 3 } },
pageOne
);
const pageOneResult = query(store, {
query: Pagination,
variables: { skip: 0, limit: 3 },
});
expect(pageOneResult.data).toEqual(pageOne);
write(
store,
{ query: Pagination, variables: { skip: 3, limit: 3 } },
pageTwo
);
InMemoryData.initDataState('write', store.data, null);
store.invalidate('Query', 'persons', { skip: 0, limit: 3 });
InMemoryData.clearDataState();
const result = query(store, {
query: Pagination,
variables: { skip: 0, limit: 3 },
});
expect(result.data).toEqual([]);
});
Closing due to inactivity and lack of reproduction
I don't have a repro but we are experiencing this in our prod RN app but not on the simulator, very weird I know, for now I had to patch it.
My hunch is that this is related to invalidating a cache key that hasn't still been populated.