@envelop/types
Advanced tools
Comparing version 1.0.0 to 1.0.1-alpha-1b981cc.0
import { Plugin } from './plugin'; | ||
import { GraphQLSchema } from 'graphql'; | ||
import { PromiseOrValue } from 'graphql/jsutils/PromiseOrValue'; | ||
import { OriginalExecuteFn, OriginalParseFn, OriginalSubscribeFn, OriginalValidateFn } from './hooks'; | ||
import { ExecuteFunction, ParseFunction, SubscribeFunction, ValidateFunction } from './graphql'; | ||
import { ArbitraryObject, Spread } from './utils'; | ||
@@ -10,6 +10,6 @@ export { ArbitraryObject } from './utils'; | ||
<InitialContext extends ArbitraryObject>(initialContext?: InitialContext): { | ||
execute: OriginalExecuteFn; | ||
validate: OriginalValidateFn; | ||
subscribe: OriginalSubscribeFn; | ||
parse: OriginalParseFn; | ||
execute: ExecuteFunction; | ||
validate: ValidateFunction; | ||
subscribe: SubscribeFunction; | ||
parse: ParseFunction; | ||
contextFactory: <ContextExtension>(contextExtension?: ContextExtension) => PromiseOrValue<Spread<[InitialContext, PluginsContext, ContextExtension]>>; | ||
@@ -16,0 +16,0 @@ schema: GraphQLSchema; |
@@ -1,3 +0,4 @@ | ||
import type { DocumentNode, GraphQLFieldResolver, GraphQLSchema, SubscriptionArgs, ExecutionResult, ExecutionArgs, GraphQLTypeResolver } from 'graphql'; | ||
import type { Maybe, PromiseOrValue, AsyncIterableIteratorOrValue } from './utils'; | ||
import type { DocumentNode, GraphQLFieldResolver, GraphQLSchema, SubscriptionArgs, ExecutionArgs, GraphQLTypeResolver, subscribe, execute, parse, validate } from 'graphql'; | ||
import type { Maybe } from './utils'; | ||
/** @private */ | ||
export declare type PolymorphicExecuteArguments = [ExecutionArgs] | [ | ||
@@ -15,3 +16,4 @@ GraphQLSchema, | ||
]; | ||
export declare type ExecuteFunction = (...args: PolymorphicExecuteArguments) => PromiseOrValue<AsyncIterableIteratorOrValue<ExecutionResult>>; | ||
export declare type ExecuteFunction = typeof execute; | ||
/** @private */ | ||
export declare type PolymorphicSubscribeArguments = [SubscriptionArgs] | [ | ||
@@ -29,2 +31,24 @@ GraphQLSchema, | ||
]; | ||
export declare type SubscribeFunction = (...args: PolymorphicSubscribeArguments) => PromiseOrValue<AsyncIterableIteratorOrValue<ExecutionResult>>; | ||
export declare type SubscribeFunction = typeof subscribe; | ||
export declare type ParseFunction = typeof parse; | ||
export declare type ValidateFunction = typeof validate; | ||
export declare type ValidateFunctionParameter = { | ||
/** | ||
* GraphQL schema instance. | ||
*/ | ||
schema: Parameters<ValidateFunction>[0]; | ||
/** | ||
* Parsed document node. | ||
*/ | ||
documentAST: Parameters<ValidateFunction>[1]; | ||
/** | ||
* The rules used for validation. | ||
* validate uses specifiedRules as exported by the GraphQL module if this parameter is undefined. | ||
*/ | ||
rules?: Parameters<ValidateFunction>[2]; | ||
/** | ||
* TypeInfo instance which is used for getting schema information during validation | ||
*/ | ||
typeInfo?: Parameters<ValidateFunction>[3]; | ||
options?: Parameters<ValidateFunction>[4]; | ||
}; |
312
hooks.d.ts
@@ -1,6 +0,6 @@ | ||
import type { DocumentNode, ExecutionArgs, ExecutionResult, GraphQLError, GraphQLResolveInfo, GraphQLSchema, parse, ParseOptions, Source, SubscriptionArgs, TypeInfo, validate, ValidationRule } from 'graphql'; | ||
import type { DocumentNode, ExecutionArgs, ExecutionResult, GraphQLError, GraphQLResolveInfo, GraphQLSchema, ParseOptions, Source, SubscriptionArgs, ValidationRule } from 'graphql'; | ||
import { Maybe } from 'graphql/jsutils/Maybe'; | ||
import { PromiseOrValue } from 'graphql/jsutils/PromiseOrValue'; | ||
import { DefaultContext } from './context-types'; | ||
import { AsyncIterableIteratorOrValue, ExecuteFunction } from '@envelop/core'; | ||
import { AsyncIterableIteratorOrValue, ExecuteFunction, ParseFunction, ValidateFunction, ValidateFunctionParameter } from '@envelop/core'; | ||
import { SubscribeFunction } from './graphql'; | ||
@@ -10,3 +10,5 @@ import { Plugin } from './plugin'; | ||
export declare type SetSchemaFn = (newSchema: GraphQLSchema) => void; | ||
/** onSchemaChange */ | ||
/** | ||
* The payload forwarded to the onSchemaChange hook. | ||
*/ | ||
export declare type OnSchemaChangeEventPayload = { | ||
@@ -16,22 +18,55 @@ schema: GraphQLSchema; | ||
}; | ||
/** | ||
* Invoked each time the schema is changed via a setSchema call. | ||
*/ | ||
export declare type OnSchemaChangeHook = (options: OnSchemaChangeEventPayload) => void; | ||
/** onPluginInit */ | ||
/** | ||
* Payload forwarded to the onPluginInit hook. | ||
*/ | ||
export declare type OnPluginInitEventPayload = { | ||
/** | ||
* Register a new plugin. | ||
*/ | ||
addPlugin: (newPlugin: Plugin<any>) => void; | ||
/** | ||
* A list of all currently active plugins. | ||
*/ | ||
plugins: Plugin<any>[]; | ||
/** | ||
* Set the GraphQL schema. | ||
*/ | ||
setSchema: SetSchemaFn; | ||
}; | ||
/** | ||
* Invoked when a plugin is initialized. | ||
*/ | ||
export declare type OnPluginInitHook = (options: OnPluginInitEventPayload) => void; | ||
/** onPluginInit */ | ||
export declare type OnEnvelopedHookEventPayload<ContextType> = { | ||
/** | ||
* Set the schema that should be used for execution. | ||
*/ | ||
setSchema: SetSchemaFn; | ||
/** | ||
* The context object. | ||
*/ | ||
context: Readonly<Maybe<ContextType>>; | ||
/** | ||
* Extend the context object with a partial. | ||
*/ | ||
extendContext: (contextExtension: Partial<ContextType>) => void; | ||
}; | ||
export declare type OnEnvelopedHook<ContextType> = (options: OnEnvelopedHookEventPayload<ContextType>) => void; | ||
/** onParse */ | ||
export declare type OriginalParseFn = typeof parse; | ||
export declare type OnParseEventPayload<ContextType> = { | ||
/** | ||
* The current context object. | ||
*/ | ||
context: Readonly<ContextType>; | ||
/** | ||
* Extend the context object with a partial. | ||
*/ | ||
extendContext: (contextExtension: Partial<ContextType>) => void; | ||
/** | ||
* The parameters that are passed to the parse call. | ||
*/ | ||
params: { | ||
@@ -41,53 +76,140 @@ source: string | Source; | ||
}; | ||
parseFn: OriginalParseFn; | ||
setParseFn: (newFn: OriginalParseFn) => void; | ||
/** | ||
* The current parse function | ||
*/ | ||
parseFn: ParseFunction; | ||
/** | ||
* Replace the current parse function | ||
*/ | ||
setParseFn: (newFn: ParseFunction) => void; | ||
/** | ||
* Set/overwrite the parsed document. | ||
* If a parsed document is set the call to the parseFn will be skipped. | ||
*/ | ||
setParsedDocument: (doc: DocumentNode) => void; | ||
}; | ||
export declare type AfterParseEventPayload<ContextType> = { | ||
/** | ||
* The current context object. | ||
*/ | ||
context: Readonly<ContextType>; | ||
/** | ||
* Extend the context object with a partial. | ||
*/ | ||
extendContext: (contextExtension: Partial<ContextType>) => void; | ||
/** | ||
* The result of the parse phase. | ||
*/ | ||
result: DocumentNode | Error | null; | ||
/** | ||
* Replace the parse result with a new result. | ||
*/ | ||
replaceParseResult: (newResult: DocumentNode | Error) => void; | ||
}; | ||
/** | ||
* Hook that is invoked after the parse function has been invoked. | ||
*/ | ||
export declare type AfterParseHook<ContextType> = (options: AfterParseEventPayload<ContextType>) => void; | ||
/** | ||
* Hook that is invoked before the parse function is invoked. | ||
*/ | ||
export declare type OnParseHook<ContextType> = (options: OnParseEventPayload<ContextType>) => void | AfterParseHook<ContextType>; | ||
/** onValidate */ | ||
export declare type OriginalValidateFn = typeof validate; | ||
/** | ||
* Payload forwarded to the onValidate hook. | ||
*/ | ||
export declare type OnValidateEventPayload<ContextType> = { | ||
/** | ||
* The current context object. | ||
*/ | ||
context: Readonly<ContextType>; | ||
/** | ||
* Extend the context object with a partial. | ||
*/ | ||
extendContext: (contextExtension: Partial<ContextType>) => void; | ||
params: { | ||
schema: GraphQLSchema; | ||
documentAST: DocumentNode; | ||
rules?: ReadonlyArray<ValidationRule>; | ||
typeInfo?: TypeInfo; | ||
options?: { | ||
maxErrors?: number; | ||
}; | ||
}; | ||
/** | ||
* The parameters with which the validate function will be invoked. | ||
*/ | ||
params: ValidateFunctionParameter; | ||
/** | ||
* Register a validation rule that will be used for the validate invocation. | ||
*/ | ||
addValidationRule: (rule: ValidationRule) => void; | ||
validateFn: OriginalValidateFn; | ||
setValidationFn: (newValidate: OriginalValidateFn) => void; | ||
/** | ||
* The current validate function that will be invoked. | ||
*/ | ||
validateFn: ValidateFunction; | ||
/** | ||
* Overwrite the current validate function. | ||
*/ | ||
setValidationFn: (newValidate: ValidateFunction) => void; | ||
/** | ||
* Set a validation error result and skip the validate invocation. | ||
*/ | ||
setResult: (errors: readonly GraphQLError[]) => void; | ||
}; | ||
/** | ||
* Payload forwarded to the afterValidate hook. | ||
*/ | ||
export declare type AfterValidateEventPayload<ContextType> = { | ||
/** | ||
* The current context object. | ||
*/ | ||
context: Readonly<ContextType>; | ||
/** | ||
* Extend the context object with a partial. | ||
*/ | ||
extendContext: (contextExtension: Partial<ContextType>) => void; | ||
/** | ||
* Whether the validation raised any errors or not. | ||
*/ | ||
valid: boolean; | ||
/** | ||
* An array of errors that were raised during the validation phase. | ||
* The array is empty if no errors were raised. | ||
*/ | ||
result: readonly GraphQLError[]; | ||
}; | ||
/** | ||
* AfterValidateHook is invoked after the validate function has been invoked. | ||
*/ | ||
export declare type AfterValidateHook<ContextType> = (options: AfterValidateEventPayload<ContextType>) => void; | ||
/** | ||
* The OnValidateHook is invoked before the validate function has been invoked. | ||
*/ | ||
export declare type OnValidateHook<ContextType> = (options: OnValidateEventPayload<ContextType>) => void | AfterValidateHook<ContextType>; | ||
/** onContextBuilding */ | ||
/** | ||
* The payload forwarded to the onContextBuilding hook. | ||
*/ | ||
export declare type OnContextBuildingEventPayload<ContextType> = { | ||
/** | ||
* The current context object. | ||
*/ | ||
context: Readonly<ContextType>; | ||
/** | ||
* Extend the context object with a partial. | ||
*/ | ||
extendContext: (contextExtension: Partial<ContextType>) => void; | ||
}; | ||
/** | ||
* The payload forwarded to the afterContextBuilding hook. | ||
*/ | ||
export declare type AfterContextBuildingEventPayload<ContextType> = { | ||
/** | ||
* The current context object. | ||
*/ | ||
context: ContextType; | ||
/** | ||
* Extend the context object with a partial. | ||
*/ | ||
extendContext: (contextExtension: Partial<ContextType>) => void; | ||
context: ContextType; | ||
}; | ||
/** | ||
* Invoked after the context has been builded. | ||
*/ | ||
export declare type AfterContextBuildingHook<ContextType> = (options: AfterContextBuildingEventPayload<ContextType>) => PromiseOrValue<void>; | ||
/** | ||
* Invoked before the context has been builded. | ||
* Return a AfterContextBuildingHook, which is invoked after the context building has been finished. | ||
*/ | ||
export declare type OnContextBuildingHook<ContextType> = (options: OnContextBuildingEventPayload<ContextType>) => PromiseOrValue<void | AfterContextBuildingHook<ContextType>>; | ||
/** onResolverCalled */ | ||
export declare type ResolverFn<ParentType = unknown, ArgsType = DefaultArgs, ContextType = unknown, ResultType = unknown> = (root: ParentType, args: ArgsType, context: ContextType, info: GraphQLResolveInfo) => PromiseOrValue<ResultType>; | ||
@@ -108,64 +230,190 @@ export declare type OnBeforeResolverCalledEventPayload<ParentType = unknown, ArgsType = DefaultArgs, ContextType = unknown, ResultType = unknown> = { | ||
export declare type OnResolverCalledHook<ParentType = unknown, ArgsType = DefaultArgs, ContextType = DefaultContext, ResultType = unknown> = (options: OnBeforeResolverCalledEventPayload<ParentType, ArgsType, ContextType, ResultType>) => PromiseOrValue<void | AfterResolverHook>; | ||
/** onExecute */ | ||
/** | ||
* Execution arguments with inferred context value type. | ||
*/ | ||
export declare type TypedExecutionArgs<ContextType> = Omit<ExecutionArgs, 'contextValue'> & { | ||
contextValue: ContextType; | ||
}; | ||
export declare type OriginalExecuteFn = ExecuteFunction; | ||
/** | ||
* Payload that is passed to the onExecute hook. | ||
*/ | ||
export declare type OnExecuteEventPayload<ContextType> = { | ||
executeFn: OriginalExecuteFn; | ||
/** | ||
* Current execute function that will be used for execution. | ||
*/ | ||
executeFn: ExecuteFunction; | ||
/** | ||
* Arguments the execute function will be invoked with. | ||
*/ | ||
args: TypedExecutionArgs<ContextType>; | ||
setExecuteFn: (newExecute: OriginalExecuteFn) => void; | ||
/** | ||
* Replace the current execute function with a new one. | ||
*/ | ||
setExecuteFn: (newExecute: ExecuteFunction) => void; | ||
/** | ||
* Set a execution result and skip calling the execute function. | ||
*/ | ||
setResultAndStopExecution: (newResult: ExecutionResult) => void; | ||
/** | ||
* Extend the context object with a partial. | ||
*/ | ||
extendContext: (contextExtension: Partial<ContextType>) => void; | ||
}; | ||
/** | ||
* Payload that is passed to the onExecuteDone hook. | ||
*/ | ||
export declare type OnExecuteDoneHookResultOnNextHookPayload = { | ||
/** | ||
* The execution result. | ||
*/ | ||
result: ExecutionResult; | ||
/** | ||
* Replace the execution result with a new execution result. | ||
*/ | ||
setResult: (newResult: ExecutionResult) => void; | ||
}; | ||
/** | ||
* Hook that is invoked for each value a AsyncIterable returned from execute publishes. | ||
*/ | ||
export declare type OnExecuteDoneHookResultOnNextHook = (payload: OnExecuteDoneHookResultOnNextHookPayload) => void | Promise<void>; | ||
/** | ||
* Hook that is invoked after a AsyncIterable returned from execute completes. | ||
*/ | ||
export declare type OnExecuteDoneHookResultOnEndHook = () => void; | ||
/** | ||
* Hook for hooking into AsyncIterables returned from execute. | ||
*/ | ||
export declare type OnExecuteDoneHookResult = { | ||
/** | ||
* Hook that is invoked for each value a AsyncIterable returned from execute publishes. | ||
*/ | ||
onNext?: OnExecuteDoneHookResultOnNextHook; | ||
/** | ||
* Hook that is invoked after a AsyncIterable returned from execute completes. | ||
*/ | ||
onEnd?: OnExecuteDoneHookResultOnEndHook; | ||
}; | ||
/** | ||
* Payload with which the onExecuteDone hook is invoked. | ||
*/ | ||
export declare type OnExecuteDoneEventPayload = { | ||
/** | ||
* The execution result returned from the execute function. | ||
* Can return an AsyncIterable if a graphql.js that has defer/stream implemented is used. | ||
*/ | ||
result: AsyncIterableIteratorOrValue<ExecutionResult>; | ||
/** | ||
* Replace the execution result with a new execution result. | ||
*/ | ||
setResult: (newResult: AsyncIterableIteratorOrValue<ExecutionResult>) => void; | ||
}; | ||
/** | ||
* Hook that is invoked after the execute function has been invoked. | ||
* Allows returning a OnExecuteDoneHookResult for hooking into stream values if execute returned an AsyncIterable. | ||
*/ | ||
export declare type OnExecuteDoneHook = (options: OnExecuteDoneEventPayload) => void | OnExecuteDoneHookResult; | ||
/** | ||
* Result returned from the onExecute hook result for hooking into subsequent phases. | ||
*/ | ||
export declare type OnExecuteHookResult<ContextType> = { | ||
/** | ||
* Invoked with the execution result returned from execute. | ||
*/ | ||
onExecuteDone?: OnExecuteDoneHook; | ||
/** | ||
* Invoked before each resolver has been invoked during the execution phase. | ||
*/ | ||
onResolverCalled?: OnResolverCalledHook<any, DefaultArgs, ContextType>; | ||
}; | ||
/** | ||
* onExecute hook that is invoked before the execute function is invoked. | ||
*/ | ||
export declare type OnExecuteHook<ContextType> = (options: OnExecuteEventPayload<ContextType>) => PromiseOrValue<void | OnExecuteHookResult<ContextType>>; | ||
/** onSubscribe */ | ||
/** | ||
* Subscription arguments with inferred context value type. | ||
*/ | ||
export declare type TypedSubscriptionArgs<ContextType> = Omit<SubscriptionArgs, 'contextValue'> & { | ||
contextValue: ContextType; | ||
}; | ||
export declare type OriginalSubscribeFn = SubscribeFunction; | ||
/** | ||
* Payload with which the onSubscribe hook is invoked. | ||
*/ | ||
export declare type OnSubscribeEventPayload<ContextType> = { | ||
subscribeFn: OriginalSubscribeFn; | ||
/** | ||
* Current subscribe function that will be used for setting up the subscription. | ||
*/ | ||
subscribeFn: SubscribeFunction; | ||
/** | ||
* Current arguments with which the subscribe function will be invoked. | ||
*/ | ||
args: TypedSubscriptionArgs<ContextType>; | ||
setSubscribeFn: (newSubscribe: OriginalSubscribeFn) => void; | ||
/** | ||
* Replace the current subscribe function with a new one that will be used for setting up the subscription. | ||
*/ | ||
setSubscribeFn: (newSubscribe: SubscribeFunction) => void; | ||
/** | ||
* Extend the context object with a partial. | ||
*/ | ||
extendContext: (contextExtension: Partial<ContextType>) => void; | ||
}; | ||
/** | ||
* Payload with which the onSubscribeResult hook is invoked. | ||
*/ | ||
export declare type OnSubscribeResultEventPayload = { | ||
/** | ||
* The current execution result. | ||
*/ | ||
result: AsyncIterableIterator<ExecutionResult> | ExecutionResult; | ||
/** | ||
* Replace the current execution result with a new execution result. | ||
*/ | ||
setResult: (newResult: AsyncIterableIterator<ExecutionResult> | ExecutionResult) => void; | ||
}; | ||
export declare type OnSubscribeResultResultOnNextHookPayload = { | ||
/** | ||
* The current execution result. | ||
*/ | ||
result: ExecutionResult; | ||
/** | ||
* Replace the current execution result with a new execution result. | ||
*/ | ||
setResult: (newResult: ExecutionResult) => void; | ||
}; | ||
/** | ||
* Hook invoked for each value published by the AsyncIterable returned from subscribe. | ||
*/ | ||
export declare type OnSubscribeResultResultOnNextHook = (payload: OnSubscribeResultResultOnNextHookPayload) => void | Promise<void>; | ||
/** | ||
* Hook invoked after the AsyncIterable returned from subscribe completes. | ||
*/ | ||
export declare type OnSubscribeResultResultOnEndHook = () => void; | ||
export declare type OnSubscribeResultResult = { | ||
/** | ||
* Invoked for each value published by the AsyncIterable returned from subscribe. | ||
*/ | ||
onNext?: OnSubscribeResultResultOnNextHook; | ||
/** | ||
* Invoked after the AsyncIterable returned from subscribe completes. | ||
*/ | ||
onEnd?: OnSubscribeResultResultOnEndHook; | ||
}; | ||
/** | ||
* Hook that is invoked with the result of the subscribe call. | ||
* Return a OnSubscribeResultResult for hooking into the AsyncIterable returned from subscribe. | ||
*/ | ||
export declare type SubscribeResultHook = (options: OnSubscribeResultEventPayload) => void | OnSubscribeResultResult; | ||
export declare type OnSubscribeHookResult<ContextType> = { | ||
/** | ||
* Invoked with the result returned from subscribe. | ||
*/ | ||
onSubscribeResult?: SubscribeResultHook; | ||
/** | ||
* Invoked before each resolver has been invoked during the execution phase. | ||
*/ | ||
onResolverCalled?: OnResolverCalledHook<ContextType>; | ||
}; | ||
/** | ||
* onSubscribe hook that is invoked before the subscribe function is called. | ||
* Return a OnSubscribeHookResult for hooking into phase after the subscribe function has been called. | ||
*/ | ||
export declare type OnSubscribeHook<ContextType> = (options: OnSubscribeEventPayload<ContextType>) => PromiseOrValue<void | OnSubscribeHookResult<ContextType>>; |
{ | ||
"name": "@envelop/types", | ||
"version": "1.0.0", | ||
"version": "1.0.1-alpha-1b981cc.0", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "peerDependencies": { |
import { OnEnvelopedHook } from '@envelop/core'; | ||
import { OnContextBuildingHook, OnExecuteHook, OnParseHook, OnPluginInitHook, OnSchemaChangeHook, OnSubscribeHook, OnValidateHook } from './hooks'; | ||
export interface Plugin<PluginContext extends Record<string, any> = {}> { | ||
/** | ||
* Invoked for each call to getEnveloped. | ||
*/ | ||
onEnveloped?: OnEnvelopedHook<PluginContext>; | ||
/** | ||
* Invoked each time the GraphQL schema has been replaced from within a plugin. | ||
*/ | ||
onSchemaChange?: OnSchemaChangeHook; | ||
/** | ||
* Invoked when a plugin is initialized. | ||
*/ | ||
onPluginInit?: OnPluginInitHook; | ||
/** | ||
* Invoked for each execute call. | ||
*/ | ||
onExecute?: OnExecuteHook<PluginContext>; | ||
/** | ||
* Invoked for each subscribe call. | ||
*/ | ||
onSubscribe?: OnSubscribeHook<PluginContext>; | ||
/** | ||
* Invoked for each parse call. | ||
*/ | ||
onParse?: OnParseHook<PluginContext>; | ||
/** | ||
* Invoked for each validate call. | ||
*/ | ||
onValidate?: OnValidateHook<PluginContext>; | ||
/** | ||
* Invoked for each time the context is builded. | ||
*/ | ||
onContextBuilding?: OnContextBuildingHook<PluginContext>; | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
22250
563
2