Skip to content

Commit f4a2aab

Browse files
committed
feat(handler): Custom GraphQL getOperationAST option
1 parent 6ef4c57 commit f4a2aab

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

docs/interfaces/HandlerOptions.md

+26
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
- [context](HandlerOptions.md#context)
1616
- [execute](HandlerOptions.md#execute)
17+
- [getOperationAST](HandlerOptions.md#getoperationast)
1718
- [onOperation](HandlerOptions.md#onoperation)
1819
- [onSubscribe](HandlerOptions.md#onsubscribe)
1920
- [parse](HandlerOptions.md#parse)
@@ -61,6 +62,31 @@ a GraphQLError will be thrown immediately explaining the invalid input.
6162

6263
___
6364

65+
### getOperationAST
66+
67+
`Optional` **getOperationAST**: (`documentAST`: `DocumentNode`, `operationName?`: `Maybe`<`string`\>) => `Maybe`<`OperationDefinitionNode`\>
68+
69+
#### Type declaration
70+
71+
▸ (`documentAST`, `operationName?`): `Maybe`<`OperationDefinitionNode`\>
72+
73+
Returns an operation AST given a document AST and optionally an operation
74+
name. If a name is not provided, an operation is only returned if only one is
75+
provided in the document.
76+
77+
##### Parameters
78+
79+
| Name | Type |
80+
| :------ | :------ |
81+
| `documentAST` | `DocumentNode` |
82+
| `operationName?` | `Maybe`<`string`\> |
83+
84+
##### Returns
85+
86+
`Maybe`<`OperationDefinitionNode`\>
87+
88+
___
89+
6490
### onOperation
6591

6692
`Optional` **onOperation**: (`req`: [`Request`](Request.md)<`RawRequest`\>, `args`: `ExecutionArgs`, `result`: `ExecutionResult`<`ObjMap`<`unknown`\>, `ObjMap`<`unknown`\>\>) => `void` \| [`Response`](../README.md#response) \| `ExecutionResult`<`ObjMap`<`unknown`\>, `ObjMap`<`unknown`\>\> \| `Promise`<`void` \| [`Response`](../README.md#response) \| `ExecutionResult`<`ObjMap`<`unknown`\>, `ObjMap`<`unknown`\>\>\>

src/handler.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
execute as graphqlExecute,
1313
parse as graphqlParse,
1414
DocumentNode,
15-
getOperationAST,
15+
getOperationAST as graphqlGetOperationAST,
1616
OperationTypeNode,
1717
} from 'graphql';
1818
import { isResponse, Request, RequestParams, Response } from './common';
@@ -86,6 +86,10 @@ export interface HandlerOptions<RawRequest = unknown> {
8686
* GraphQL parse function allowing you to apply a custom parser.
8787
*/
8888
parse?: typeof graphqlParse;
89+
/**
90+
* GraphQL operation AST getter used for detecting the operation type.
91+
*/
92+
getOperationAST?: typeof graphqlGetOperationAST;
8993
/**
9094
* The subscribe callback executed right after processing the request
9195
* before proceeding with the GraphQL operation execution.
@@ -215,6 +219,7 @@ export function createHandler<RawRequest = unknown>(
215219
validate = graphqlValidate,
216220
execute = graphqlExecute,
217221
parse = graphqlParse,
222+
getOperationAST = graphqlGetOperationAST,
218223
onSubscribe,
219224
onOperation,
220225
} = options;

0 commit comments

Comments
 (0)