Skip to content

Commit 6914a97

Browse files
Document optimisticResponse handling of GraphQL errors in optimistic UI (#13000)
* Document handling of GraphQL errors in optimistic UI Add explanation for handling GraphQL errors in optimistic updates. It wasn't obvious what happens when a mutation fails and error is returned from the server. Adding one extra item in the lifecycle explanation makes it much clearer what happens * Use active voice --------- Co-authored-by: Jerel Miller <[email protected]>
1 parent 63d1649 commit 6914a97

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

docs/source/performance/optimistic-ui.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ As this example shows, the value of `optimisticResponse` is an object that match
7373

7474
5. Apollo Client notifies all affected queries again. The associated components re-render, but if the server's response matches our `optimisticResponse`, this is invisible to the user.
7575

76+
6. If the mutation returns a GraphQL error, Apollo Client discards the optimistic version of the object and rolls back to the previous state.
77+
7678
## Bailing out of an optimistic update
7779

7880
In some cases you may want to skip an optimistic update. For example, you may want to perform an optimistic update _only_ when certain variables are passed to the mutation. To skip an update, pass a function to the `optimisticResponse` option and return the `IGNORE` sentinel object available on the second argument to bail out of the optimistic update.

0 commit comments

Comments
 (0)