urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
https://urql.dev/goto/docs
MIT License
8.55k stars 444 forks source link

feat(graphcache): track types in the data-structure #3501

Closed JoviDeCroock closed 4 months ago

JoviDeCroock commented 5 months ago

Related to #3470

Summary

This starts tracking a mapping of __typename to a list of entityKey, this enables us to perform operations like invalidate('Todo') which would invalidate every entityKey of the Todo type.

We add non-root typenames when going through the write operation and we clean up entities in the list when we are going through gc runs.

In the future this can instruct us for operations where we can't derive an entity i.e. a create-mutation will invalidate all entities of its own type to ensure we don't run into stale values which leaves us with the scalar return case which won't automatically be handled.

The PR explicitly does not add the updater logic yet so we can see that the explicit API surface does not grow, we support more cases instead.

Set of changes

Questions

Should we support invalidating a full type with field and arguments i.e. invalidate('Todo', 'author') would go through every Todo key and explicitly invalidate the Author field.

Follow-ups

changeset-bot[bot] commented 5 months ago

🦋 Changeset detected

Latest commit: 8125b32da472fcb71bb367e6b41494f5752b3550

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------------------------- | ----- | | @urql/exchange-graphcache | Minor |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR