Skip to content

Commit

Permalink
Update local state docs
Browse files Browse the repository at this point in the history
* Use the term mutation more to help developers search for what they
  want
* Wordsmith existing section to emphasize that local-only mutations
  aren't really "a thing" anymore - use reactive variables or writeQuery
  / writeFragment instead
  • Loading branch information
bignimbus committed Nov 12, 2022
1 parent 6875d3c commit 96629d8
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions docs/source/local-state/managing-state-with-field-policies.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ That's it! The `@client` directive tells Apollo Client that `isInCart` is a loca
>
> </ExpansionPanel>
## Storing
## Storing and mutations
You can use Apollo Client to query local state, regardless of how you _store_ that state. Apollo Client provides a couple of optional but helpful mechanisms for representing local state:
You can use Apollo Client to query and modify local state, regardless of how you _store_ that state. Apollo Client provides a couple of optional but helpful mechanisms for representing local state:
* [Reactive variables](#storing-local-state-in-reactive-variables)
* [The Apollo Client cache itself](#storing-local-state-in-the-cache)
> **Note:** Apollo Client >= 3 no longer recommends the [local resolver](./local-resolvers) approach of using `client.mutate` / `useMutation` combined with an `@client` mutation operation to [update local state](./local-resolvers/#local-resolvers). To update local state, we recommend using [`writeQuery`](../caching/cache-interaction/#writequery), [`writeFragment`](../caching/cache-interaction/#writefragment), or [reactive variables](./reactive-variables/).
It's tempting to think of local-only mutations as being expressed similarly to other local-only fields. When using previous versions of Apollo Client, developers would define local-only mutations using `@client`. They would then use [local resolvers](./local-resolvers) to handle `client.mutate` / `useMutation` calls. This is no longer the case, however. For Apollo Client version >= 3 users we recommend using [`writeQuery`](../caching/cache-interaction/#writequery), [`writeFragment`](../caching/cache-interaction/#writefragment), or [reactive variables](./reactive-variables/) to manage local state.
### Storing local state in reactive variables
### Storing and updating local state with reactive variables
Apollo Client [reactive variables](./reactive-variables) are great for representing local state:
Expand Down Expand Up @@ -238,7 +238,7 @@ As with the preceding `useQuery` example, whenever the `cartItemsVar` variable i

> **Important:** If you call `cartItemsVar()` instead of `useReactiveVar(cartItemsVar)` in the example above, future variable updates _do not_ cause the `Cart` component to rerender.
### Storing local state in the cache
### Storing and modifying local state in the cache

Storing local state directly in the Apollo Client cache provides some advantages, but usually requires more code than [using reactive variables](#storing-local-state-in-reactive-variables):

Expand Down

0 comments on commit 96629d8

Please sign in to comment.