Skip to content

Commit 71f049c

Browse files
authored
Add updater docs for #3843 (#3851)
1 parent 3396ba7 commit 71f049c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

docs/api/graphcache.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ given mutation field or subscription field is written to the cache. These side-e
106106
to update data in the cache that is implicitly changed on the GraphQL API, that _Graphcache_ can't
107107
know about automatically.
108108

109+
For mutation fields that don't have an updater, Graphcache has a fallback: if a returned entity
110+
isn't currently found in the cache, it assumes a create-mutation and invalidates cached
111+
entities of that type. This behavior was introduced in Graphcache v7 and is skipped once an updater
112+
for the mutation field is added.
113+
109114
```ts
110115
interface UpdatesConfig {
111116
Mutation: {

docs/graphcache/cache-updates.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ cacheExchange({
5959
});
6060
```
6161

62+
## Default mutation invalidation
63+
64+
Starting in [Graphcache v7](https://github.com/urql-graphql/urql/blob/main/exchanges/graphcache/CHANGELOG.md#700),
65+
mutations without a configured `updates.Mutation.<fieldName>` updater have a fallback behavior:
66+
67+
- If the mutation returns an entity that can't be found in the cache yet, Graphcache treats this as
68+
a "create" mutation.
69+
- Graphcache then invalidates cached entities of the same `__typename` as the one returned from the mutation, which can trigger related queries to refetch.
70+
71+
As soon as you define an updater for that mutation field, this fallback behavior no longer runs and
72+
your updater fully controls what happens after the mutation write.
73+
6274
An "updater" may be attached to a `Mutation` or `Subscription` field and accepts four positional
6375
arguments, which are the same as [the resolvers' arguments](./local-resolvers.md):
6476

0 commit comments

Comments
 (0)