Skip to content

Commit 1dc4186

Browse files
authored
docs(cancel): add graphql-request example (TanStack#2948)
1 parent c1ae82b commit 1dc4186

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

docs/src/pages/guides/query-cancellation.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@ const query = useQuery('todos', ({ signal }) => {
9797
})
9898
```
9999
100+
## Using `graphql-request`
101+
102+
An `AbortSignal` can be set in the `GraphQLClient` constructor.
103+
104+
```js
105+
const query = useQuery('todos', ({ signal }) => {
106+
const client = new GraphQLClient(endpoint, {
107+
signal,
108+
});
109+
return client.request(query, variables)
110+
})
111+
```
112+
100113
## Manual Cancellation
101114
102115
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.

0 commit comments

Comments
 (0)