graphql-http / handler / HandlerOptions
handler.HandlerOptions
| Name | Type |
|---|---|
RequestRaw |
unknown |
RequestContext |
unknown |
Context |
extends OperationContext = undefined |
- context
- execute
- formatError
- getOperationAST
- onOperation
- onSubscribe
- parse
- parseRequestParams
- rootValue
- schema
- validate
- validationRules
• Optional context: Context | (req: Request<RequestRaw, RequestContext>, params: RequestParams) => Response | Context | Promise<Response | Context>
A value which is provided to every resolver and holds important contextual information like the currently logged in user, or access to a database.
• Optional execute: (args: ExecutionArgs) => PromiseOrValue<ExecutionResult>
▸ (args): PromiseOrValue<ExecutionResult>
Is the execute function from GraphQL which is
used to execute the query and mutation operations.
| Name | Type |
|---|---|
args |
ExecutionArgs |
PromiseOrValue<ExecutionResult>
• Optional formatError: FormatError
Format handled errors to your satisfaction. Either GraphQL errors or safe request processing errors are meant by "handled errors".
If multiple errors have occurred, all of them will be mapped using this formatter.
• Optional getOperationAST: (documentAST: DocumentNode, operationName?: Maybe<string>) => Maybe<OperationDefinitionNode>
▸ (documentAST, operationName?): Maybe<OperationDefinitionNode>
GraphQL operation AST getter used for detecting the operation type.
| Name | Type |
|---|---|
documentAST |
DocumentNode |
operationName? |
Maybe<string> |
Maybe<OperationDefinitionNode>
• Optional onOperation: (req: Request<RequestRaw, RequestContext>, args: OperationArgs<Context>, result: ExecutionResult<ObjMap<unknown>, ObjMap<unknown>>) => void | ExecutionResult<ObjMap<unknown>, ObjMap<unknown>> | Response | Promise<void | ExecutionResult<ObjMap<unknown>, ObjMap<unknown>> | Response>
▸ (req, args, result): void | ExecutionResult<ObjMap<unknown>, ObjMap<unknown>> | Response | Promise<void | ExecutionResult<ObjMap<unknown>, ObjMap<unknown>> | Response>
Executed after the operation call resolves.
The OperationResult argument is the result of operation
execution. It can be an iterator or already a value.
Use this callback to listen for GraphQL operations and execution result manipulation.
If you want to respond to the client with a custom status and/or body,
you should do by returning a Request argument which will stop
further execution.
| Name | Type |
|---|---|
req |
Request<RequestRaw, RequestContext> |
args |
OperationArgs<Context> |
result |
ExecutionResult<ObjMap<unknown>, ObjMap<unknown>> |
void | ExecutionResult<ObjMap<unknown>, ObjMap<unknown>> | Response | Promise<void | ExecutionResult<ObjMap<unknown>, ObjMap<unknown>> | Response>
• Optional onSubscribe: (req: Request<RequestRaw, RequestContext>, params: RequestParams) => void | ExecutionResult<ObjMap<unknown>, ObjMap<unknown>> | Response | OperationArgs<Context> | readonly GraphQLError[] | Promise<void | ExecutionResult<ObjMap<unknown>, ObjMap<unknown>> | Response | OperationArgs<Context> | readonly GraphQLError[]>
▸ (req, params): void | ExecutionResult<ObjMap<unknown>, ObjMap<unknown>> | Response | OperationArgs<Context> | readonly GraphQLError[] | Promise<void | ExecutionResult<ObjMap<unknown>, ObjMap<unknown>> | Response | OperationArgs<Context> | readonly GraphQLError[]>
The subscribe callback executed right after processing the request before proceeding with the GraphQL operation execution.
If you return ExecutionResult from the callback, it will be used
directly for responding to the request. Useful for implementing a response
cache.
If you return ExecutionArgs from the callback, it will be used instead of
trying to build one internally. In this case, you are responsible for providing
a ready set of arguments which will be directly plugged in the operation execution.
You must validate the ExecutionArgs yourself if returning them.
If you return an array of GraphQLError from the callback, they will be reported
to the client while complying with the spec.
Omitting the fields contextValue from the returned ExecutionArgs will use the
provided context option, if available.
Useful for preparing the execution arguments following a custom logic. A typical use-case is persisted queries. You can identify the query from the request parameters and supply the appropriate GraphQL operation execution arguments.
If you want to respond to the client with a custom status and/or body,
you should do by returning a Request argument which will stop
further execution.
| Name | Type |
|---|---|
req |
Request<RequestRaw, RequestContext> |
params |
RequestParams |
void | ExecutionResult<ObjMap<unknown>, ObjMap<unknown>> | Response | OperationArgs<Context> | readonly GraphQLError[] | Promise<void | ExecutionResult<ObjMap<unknown>, ObjMap<unknown>> | Response | OperationArgs<Context> | readonly GraphQLError[]>
• Optional parse: (source: string | Source, options?: ParseOptions) => DocumentNode
▸ (source, options?): DocumentNode
GraphQL parse function allowing you to apply a custom parser.
| Name | Type |
|---|---|
source |
string | Source |
options? |
ParseOptions |
DocumentNode
• Optional parseRequestParams: ParseRequestParams<RequestRaw, RequestContext>
The request parser for an incoming GraphQL request.
Read more about it in ParseRequestParams.
• Optional rootValue: unknown
The GraphQL root value or resolvers to go alongside the execution. Learn more about them here: https://graphql.org/learn/execution/#root-fields-resolvers.
If you return from onSubscribe, and the returned value is
missing the rootValue field, the relevant operation root
will be used instead.
• Optional schema: GraphQLSchema | (req: Request<RequestRaw, RequestContext>, args: Omit<OperationArgs<Context>, "schema">) => Response | GraphQLSchema | Promise<Response | GraphQLSchema>
The GraphQL schema on which the operations will be executed and validated against.
If a function is provided, it will be called on every operation request allowing you to manipulate schema dynamically.
If the schema is left undefined, you're trusted to
provide one in the returned ExecutionArgs from the
onSubscribe callback.
If you want to respond to the client with a custom status and/or body,
you should do by returning a Request argument which will stop
further execution.
• Optional validate: (schema: GraphQLSchema, documentAST: DocumentNode, rules?: readonly ValidationRule[], options?: {}, typeInfo?: TypeInfo) => ReadonlyArray<GraphQLError>
▸ (schema, documentAST, rules?, options?, typeInfo?): ReadonlyArray<GraphQLError>
A custom GraphQL validate function allowing you to apply your own validation rules.
Will not be used when implementing a custom onSubscribe.
| Name | Type | Description |
|---|---|---|
schema |
GraphQLSchema |
- |
documentAST |
DocumentNode |
- |
rules? |
readonly ValidationRule[] |
- |
options? |
Object |
- |
typeInfo? |
TypeInfo |
Deprecated will be removed in 17.0.0 |
ReadonlyArray<GraphQLError>
• Optional validationRules: readonly ValidationRule[] | (req: Request<RequestRaw, RequestContext>, args: OperationArgs<Context>, specifiedRules: readonly ValidationRule[]) => readonly ValidationRule[] | Promise<readonly ValidationRule[]>
The validation rules for running GraphQL validate.
When providing an array, the rules will be APPENDED to the default
specifiedRules array provided by the graphql-js module.
Alternatively, providing a function instead will OVERWRITE the defaults
and use exclusively the rules returned by the function. The third (last)
argument of the function are the default specifiedRules array provided
by the graphql-js module, you're free to prepend/append the defaults to
your rule set, or omit them altogether.