import { OnContextBuildingHook, OnEnvelopedHook, OnExecuteHook, OnParseHook, OnPluginInitHook, OnSchemaChangeHook, OnSubscribeHook, OnValidateHook } from './hooks.js'; import type { PromiseOrValue } from './utils.js'; export interface Plugin = {}> { /** * Instrumentation wrapping each phases, including hooks executions. */ instrumentation?: Instrumentation; /** * Invoked for each call to getEnveloped. */ onEnveloped?: OnEnvelopedHook; /** * 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; /** * Invoked for each subscribe call. */ onSubscribe?: OnSubscribeHook; /** * Invoked for each parse call. */ onParse?: OnParseHook; /** * Invoked for each validate call. */ onValidate?: OnValidateHook; /** * Invoked for each time the context is builded. */ onContextBuilding?: OnContextBuildingHook; } export type Instrumentation> = { /** * Wraps the initialization phase (`envelop` function call and `onEnvelop` hooks) */ init?: (payload: { context: TContext; }, wrapped: () => void) => void; /** * Wraps the parse phase (`parse` function call and `onParse` hooks) */ parse?: (payload: { context: TContext; }, wrapped: () => void) => void; /** * Wraps the validate phase (`validate` function call and `onValidate` hooks) */ validate?: (payload: { context: TContext; }, wrapped: () => void) => void; /** * Wraps the context building phase (`buildContext` function call) */ context?: (payload: { context: TContext; }, wrapped: () => void) => void; /** * Wraps the execute phase (`execute` function call and `onExecute` hooks) */ execute?: (payload: { context: TContext; }, wrapped: () => PromiseOrValue) => PromiseOrValue; /** * Wraps the subscribe phase (`subscribe` function call and `onSubsrcibe` hooks) */ subscribe?: (payload: { context: TContext; }, wrapped: () => PromiseOrValue) => PromiseOrValue; };