Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
n1ru4l committed Mar 28, 2024
1 parent 4aeeb6c commit 9a07506
Show file tree
Hide file tree
Showing 8 changed files with 436 additions and 31 deletions.
6 changes: 4 additions & 2 deletions .changeset/green-badgers-work.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ The execution of subsequent GraphQL resolvers is now aborted if the incoming HTT
This reduces the load of your API in case incoming requests with deep GraphQL operation selection sets are canceled.

```ts
import { createYoga, useExecutionCancellation } from 'graphql-yoga'
import { createYoga, useExecutionCancelation } from 'graphql-yoga'

const yoga = createYoga({
plugins: [useExecutionCancellation()]
plugins: [useExecutionCancelation()]
})
```

[Learn more in our docs](https://graphql-yoga.com/docs/features/execution-cancelation)

**Action Required** In order to benefit from this new feature, you need to update your integration setup for Fastify, Koa and Hapi.

```diff
Expand Down
3 changes: 3 additions & 0 deletions examples/graphql-ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"private": true,
"scripts": {
"check": "tsc --pretty --noEmit",
"dev": "cross-env NODE_ENV=development ts-node-dev --exit-child --respawn src/index.ts",
"start": "ts-node src/index.ts"
},
"dependencies": {
Expand All @@ -13,7 +14,9 @@
"ws": "8.13.0"
},
"devDependencies": {
"cross-env": "7.0.3",
"ts-node": "10.9.1",
"ts-node-dev": "2.0.0",
"typescript": "5.1.6"
}
}
27 changes: 27 additions & 0 deletions examples/request-cancelation/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "example-request-cancelation",
"version": "0.0.0",
"description": "",
"author": "Laurin Quast <[email protected]>",
"license": "MIT",
"private": true,
"module": "commonjs",
"keywords": [],
"scripts": {
"check": "tsc --pretty --noEmit",
"dev": "cross-env NODE_ENV=development ts-node-dev --exit-child --respawn src/main.ts",
"start": "ts-node src/main.ts"
},
"dependencies": {
"graphql": "16.6.0",
"graphql-yoga": "5.2.0"
},
"devDependencies": {
"@types/node": "18.16.16",
"@whatwg-node/fetch": "^0.9.17",
"cross-env": "7.0.3",
"ts-node": "10.9.1",
"ts-node-dev": "2.0.0",
"typescript": "5.1.6"
}
}
61 changes: 61 additions & 0 deletions examples/request-cancelation/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { createServer } from 'node:http';
import { createLogger, createSchema, createYoga, useExecutionCancelation } from 'graphql-yoga';

const logger = createLogger('debug');

const schema = createSchema({
typeDefs: /* GraphQL */ `
type Query {
user: User
}
type User {
id: ID!
name: String!
bestFriend: User
}
`,
resolvers: {
Query: {
async user(_, __, { request }) {
logger.info('resolving user');
await new Promise((resolve, reject) => {
const timeout = setTimeout(resolve, 5000);
request.signal.addEventListener('abort', () => {
clearTimeout(timeout);
reject(request.signal.reason);
});
});
logger.info('resolved user');

return {
id: '1',
name: 'Chewie',
};
},
},
User: {
bestFriend() {
logger.info('resolving user best friend');

return {
id: '2',
name: 'Han Solo',
};
},
},
},
});

// Provide your schema
const yoga = createYoga({
plugins: [useExecutionCancelation()],
schema,
logging: logger,
});

// Start the server and explore http://localhost:4000/graphql
const server = createServer(yoga);
server.listen(4000, () => {
console.info('Server is running on http://localhost:4000/graphql');
});
13 changes: 13 additions & 0 deletions examples/request-cancelation/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"outDir": "./dist",
"module": "commonjs",
"target": "esnext",
"lib": ["esnext"],
"moduleResolution": "node",
"sourceMap": true,
"skipLibCheck": true
},
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
66 changes: 37 additions & 29 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions website/src/pages/docs/features/_meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export default {
graphiql: 'GraphiQL',
context: 'GraphQL Context',
'error-masking': 'Error Masking',
'execution-cancelation': 'Execution Cancelation',
introspection: 'Introspection',
subscriptions: 'Subscriptions',
'file-uploads': 'File Uploads',
Expand Down
Loading

0 comments on commit 9a07506

Please sign in to comment.