Skip to content

Commit 6ef4c57

Browse files
committed
feat(handler): Custom GraphQL parse option
1 parent 99d9086 commit 6ef4c57

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

docs/interfaces/HandlerOptions.md

+25
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- [execute](HandlerOptions.md#execute)
1717
- [onOperation](HandlerOptions.md#onoperation)
1818
- [onSubscribe](HandlerOptions.md#onsubscribe)
19+
- [parse](HandlerOptions.md#parse)
1920
- [schema](HandlerOptions.md#schema)
2021
- [validate](HandlerOptions.md#validate)
2122

@@ -133,6 +134,30 @@ further execution.
133134

134135
___
135136

137+
### parse
138+
139+
`Optional` **parse**: (`source`: `string` \| `Source`, `options?`: `ParseOptions`) => `DocumentNode`
140+
141+
#### Type declaration
142+
143+
▸ (`source`, `options?`): `DocumentNode`
144+
145+
Given a GraphQL source, parses it into a Document.
146+
Throws GraphQLError if a syntax error is encountered.
147+
148+
##### Parameters
149+
150+
| Name | Type |
151+
| :------ | :------ |
152+
| `source` | `string` \| `Source` |
153+
| `options?` | `ParseOptions` |
154+
155+
##### Returns
156+
157+
`DocumentNode`
158+
159+
___
160+
136161
### schema
137162

138163
`Optional` **schema**: `GraphQLSchema` \| (`req`: [`Request`](Request.md)<`RawRequest`\>, `args`: `Omit`<`ExecutionArgs`, ``"schema"``\>) => [`Response`](../README.md#response) \| `GraphQLSchema` \| `Promise`<[`Response`](../README.md#response) \| `GraphQLSchema`\>

src/handler.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
GraphQLSchema,
1111
validate as graphqlValidate,
1212
execute as graphqlExecute,
13-
parse,
13+
parse as graphqlParse,
1414
DocumentNode,
1515
getOperationAST,
1616
OperationTypeNode,
@@ -82,6 +82,10 @@ export interface HandlerOptions<RawRequest = unknown> {
8282
* used to execute the query and mutation operations.
8383
*/
8484
execute?: typeof graphqlExecute;
85+
/**
86+
* GraphQL parse function allowing you to apply a custom parser.
87+
*/
88+
parse?: typeof graphqlParse;
8589
/**
8690
* The subscribe callback executed right after processing the request
8791
* before proceeding with the GraphQL operation execution.
@@ -210,6 +214,7 @@ export function createHandler<RawRequest = unknown>(
210214
context,
211215
validate = graphqlValidate,
212216
execute = graphqlExecute,
217+
parse = graphqlParse,
213218
onSubscribe,
214219
onOperation,
215220
} = options;

0 commit comments

Comments
 (0)