Skip to content

Commit

Permalink
docs: add TSDoc to plugin's hooks (#1880)
Browse files Browse the repository at this point in the history
Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
  • Loading branch information
EmrysMyrddin and ardatan authored Dec 12, 2024
1 parent 8bf3a9e commit 95e5ce4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-chicken-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@whatwg-node/server': patch
---

Docs for hooks
27 changes: 27 additions & 0 deletions packages/server/src/plugins/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,36 @@ import {
} from '../types.js';

export interface ServerAdapterPlugin<TServerContext = {}> {
/**
* This hook is invoked for ANY incoming HTTP request. Here you can manipulate the request,
* create a short circuit before the request handler takes it over.
*
* Warning: Exceptions thrown by this hook are not caught.
* This means they will buble up to the HTTP server underlying implementation.
* For example, the `node:http` server crashes the entire process on uncaught exceptions.
*/
onRequest?: OnRequestHook<TServerContext & ServerAdapterInitialContext>;
/**
* This hook is invoked after a HTTP request (both GraphQL and NON GraphQL) has been processed
* and after the response has been forwarded to the client. Here you can perform any cleanup
* or logging operations, or you can manipulate the outgoing response object.
*
* Warning: Exceptions thrown by this hook are not caught.
* This means they will buble up to the HTTP server underlying implementation.
* For example, the `node:http` server crashes the entire process on uncaught exceptions.
*/
onResponse?: OnResponseHook<TServerContext & ServerAdapterInitialContext>;
/**
* This hook is invoked when the server is being disposed.
* The server disposal is triggered either by the request termination or the explicit server disposal.
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html
*/
[Symbol.dispose]?: () => void;
/**
* This hook is invoked when the server is being disposed.
* The server disposal is triggered either by the request termination or the explicit server disposal.
* @see https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-2.html
*/
[Symbol.asyncDispose]?: () => PromiseLike<void> | void;
}
export type OnRequestHook<TServerContext> = (
Expand Down

0 comments on commit 95e5ce4

Please sign in to comment.