Skip to content

Commit

Permalink
Fix typos and add more code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
helfer authored Jan 26, 2017
1 parent 09acfc0 commit d4236c3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions react-docs/source/cache-updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ Once the mutation fires and the result arrives from the server (or, a result is

<h2 id="refetchQueries">Using `refetchQueries`</h2>

`refetchQueries` offers an even simpler way of updating the cache than `updateQueries`. With `refetchQueries` you can specifiy one or more queries that you want to run after a mutation completed in order to refetch the parts of the store that may have been affected by the mutation:
`refetchQueries` offers an even simpler way of updating the cache than `updateQueries`. With `refetchQueries` you can specify one or more queries that you want to run after a mutation completed in order to refetch the parts of the store that may have been affected by the mutation:

```javascript
mutate({
Expand All @@ -322,6 +322,21 @@ mutate({
})
```

A very common way of using `refetchQueries` is to import queries defined for other components to make sure that those components will be updated:

```javascript
import RepoCommentsQuery from '../queries/RepoCommentsQuery';

mutate({
//... insert comment mutation
refetchQueries: [{
query: RepoCommentsQuery,
variables: { repoFullName: 'apollostack/apollo-client' },
}],
})
```



<h2 id="resultReducers">Using `reducer`</h2>

Expand Down Expand Up @@ -372,7 +387,7 @@ As you can see, the `reducer` option can be used to achieve the same goal as `up

`refetchQueries` should be used whenever the mutation result alone is not enough to infer all the changes to the cache. `refetchQueries` is also a very good option if an extra roundtrip and possible overfetching are not of concern for your application, which is often true during prototyping. Compared with `updateQueries` and `reducer`, `refetchQueries` is the easiest to write and maintain.

`reducer` and `updateQueries` both provide similar functionality. While `reducer` is more flexible, updates based on mutations can usually be done equally well with `udpateQueries`.
`reducer` and `updateQueries` both provide similar functionality. While `reducer` is more flexible, updates based on mutations can usually be done equally well with `updateQueries`.

The main difference between the two is where the update behavior is declared. With `reducer`, the update behavior is co-located with the query itself. That means the query needs to know what actions should lead to an updated result. With `updateQueries` it is the mutation's responsibility to update all the queries that may need to know about the results of this mutation.

Expand Down

0 comments on commit d4236c3

Please sign in to comment.