Skip to content

Commit

Permalink
docs(cancel): add graphql-request example (#2948)
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudbzn committed Nov 15, 2021
1 parent c1ae82b commit 1dc4186
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/src/pages/guides/query-cancellation.md
Expand Up @@ -97,6 +97,19 @@ const query = useQuery('todos', ({ signal }) => {
})
```
## Using `graphql-request`
An `AbortSignal` can be set in the `GraphQLClient` constructor.
```js
const query = useQuery('todos', ({ signal }) => {
const client = new GraphQLClient(endpoint, {
signal,
});
return client.request(query, variables)
})
```
## Manual Cancellation
You might want to cancel a query manually. For example, if the request takes a long time to finish, you can allow the user to click a cancel button to stop the request. To do this, you just need to call `queryClient.cancelQueries(key)`, which will cancel the query and revert it back to its previous state. If `promise.cancel` is available, or you have consumed the `signal` passed to the query function, React Query will additionally also cancel the Promise.
Expand Down

1 comment on commit 1dc4186

@vercel
Copy link

@vercel vercel bot commented on 1dc4186 Nov 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.