From 96629d882cb403b4233be1e9c687ade4b9662fbc Mon Sep 17 00:00:00 2001 From: Jeff Auriemma Date: Fri, 11 Nov 2022 22:26:10 -0500 Subject: [PATCH] Update local state docs * 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 --- .../local-state/managing-state-with-field-policies.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/source/local-state/managing-state-with-field-policies.mdx b/docs/source/local-state/managing-state-with-field-policies.mdx index 857367dfc31..b6aff04079c 100644 --- a/docs/source/local-state/managing-state-with-field-policies.mdx +++ b/docs/source/local-state/managing-state-with-field-policies.mdx @@ -99,16 +99,16 @@ That's it! The `@client` directive tells Apollo Client that `isInCart` is a loca > > -## 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: @@ -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):