Skip to content

Commit

Permalink
Document code changes in #8875
Browse files Browse the repository at this point in the history
  • Loading branch information
brainkim committed Oct 1, 2021
1 parent a1af48f commit c646ee2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
14 changes: 14 additions & 0 deletions docs/shared/mutation-result.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,20 @@ The instance of Apollo Client that executed the mutation.

Can be useful for manually executing followup operations or writing data to the cache.

</td>
</tr>

<tr>
<td>
##### `reset`

`() => void`
</td>

<td>

A function which enables you to return the mutation result to its initial, uncalled state.

</td>
</tr>
</tbody>
Expand Down
4 changes: 2 additions & 2 deletions docs/source/api/react/hooks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function useLazyQuery<TData = any, TVariables = OperationVariables>(
query: DocumentNode,
options?: LazyQueryHookOptions<TData, TVariables>,
): [
(options?: QueryLazyOptions<TVariables>) => void,
(options?: QueryLazyOptions<TVariables>) => Promise<LazyQueryResult<TData, TVariables>>,
LazyQueryResult<TData, TVariables>
] {}
```
Expand All @@ -172,7 +172,7 @@ function useLazyQuery<TData = any, TVariables = OperationVariables>(

| Param | Type | Description |
| ---------------- | ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| Execute function | (options?: QueryLazyOptions&lt;TVariables&gt;) => void | Function that can be triggered to execute the suspended query. After being called, `useLazyQuery` behaves just like `useQuery`. |
| Execute function | (options?: QueryLazyOptions&lt;TVariables&gt;) => Promise&lt;LazyQueryResult&lt;TData, TVariables&gt;&gt; | Function that can be triggered to execute the suspended query. After being called, `useLazyQuery` behaves just like `useQuery`. The `useLazyQuery` function returns a promise which fulfills with a query result when the query succeeds or fails. |

**Result object**

Expand Down
27 changes: 27 additions & 0 deletions docs/source/data/mutations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,33 @@ If you find you've included more queries than you expected, you can skip or igno

To use the `onQueryUpdated` API without performing a mutation, try the [`client.refetchQueries`](./refetching/#clientrefetchqueries) method. In the standalone `client.refetchQueries` API, the `refetchQueries: [...]` mutation option is called `include: [...]`, and the `update` function is called `updateCache` for clarity. Otherwise, the same internal system powers both `client.refetchQueries` and refetching queries after a mutation.

### Resetting mutation results

Similar to the functions available from `useQuery` results, the mutation result has a `reset` function, which can be used to reset the mutation result to its initial state. This function can be used to allow the user to dismiss mutation data or errors in the UI.

```js
function LoginPage () {
const [loginMutation, loginResult] = useMutation(LOGIN_MUTATION);

return (
<>
<form>
<input class="login"/>
<input class="password"/>
<button onclick={login}>Login</button>
</form>
{
loginResult.error &&
<LoginFailedMessageWindow
message={loginResult.error.message}
onDismiss={() => loginResult.reset()}
/>
}
</>
);
}
```

## `useMutation` API

Supported options and result fields for the `useMutation` hook are listed below.
Expand Down

0 comments on commit c646ee2

Please sign in to comment.