Skip to content

Commit

Permalink
more spelling and resources
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Mar 28, 2024
1 parent b0174c3 commit aeba523
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions website/src/pages/docs/features/execution-cancellation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ server.listen(4000, () => {
```

That is all you need to do to enable execution cancellation in your Yoga server. Theoretically, you
can enable this and immediatly benefit from it without making any other adjustments within your
can enable this and immediately benefit from it without making any other adjustments within your
GraphQL schema implementation.

If you want to understand how it works and how you can adjust your resolvers to properly cancel
Expand All @@ -56,8 +56,8 @@ type User {
}
```

The `Query.user` resolver has a artifical delay of 10 seconds to simulate a long running e.g. a slow
read from a database.
The `Query.user` resolver has a artificial delay of 10 seconds to simulate a long-running operation
e.g. a slow read from a database.

```ts filename="Full Yoga Example"
import { createServer } from 'node:http'
Expand Down Expand Up @@ -134,7 +134,7 @@ query UserWithBestFriend {
}
```

For your convencience, you can copy the following `curl` command to execute the query.
For your convenience, you can copy the following `curl` command to execute the query.

```bash filename="Curl Request for executing the operation"
curl -g \
Expand Down Expand Up @@ -168,10 +168,12 @@ DEBUG Request aborted
INFO resolved user
```

The interesting part is that now `DEBUG Request aborted` is shown. At this point any further GraphQL
execution will be stopped. However, the `INFO resolved user` log is still showing up.
The interesting part is that now `DEBUG Request aborted` is shown. At this point, any further
GraphQL execution will be stopped and no other GraphQL resolvers will be invoked.

We can further adjust our server to cancel the artifical delay promise when the request is aborted
However, the `INFO resolved user` log is still showing up.

We can further adjust our server to cancel the artificial delay promise when the request is aborted
to avoid any further processing.

```ts filename="Altered server example with timer cleanup" {22-28}
Expand Down Expand Up @@ -238,8 +240,8 @@ server.listen(4000, () => {
})
```

After these adjustments, timer will be cleaned up properly, and `INFO resolved user`, will no longer
show up in the logs.
After these adjustments, the timer will be cleaned up properly, and `INFO resolved user`, will no
longer show up in the logs.

```bash filename="Server Logs after timer cleanup"
DEBUG Parsing request to extract GraphQL parameters
Expand Down Expand Up @@ -288,3 +290,14 @@ server.listen(4000, () => {
console.info('Server is running on http://localhost:4000/graphql')
})
```

## Further Resources

The execution cancelation API is built on top of the `AbortController` and `AbortSignal` APIs.

- [MDN AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) and
- [MDN AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) APIs

The execution cancelation is a feature of our GraphQL executor that is a fork of `graphql-js`.

- [`@graphql-tools/executor`](https://github.com/ardatan/graphql-tools/tree/master/packages/executor)

0 comments on commit aeba523

Please sign in to comment.