-
Notifications
You must be signed in to change notification settings - Fork 2k
/
index.ts
47 lines (43 loc) · 1.41 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {
GraphQLServiceContext,
GraphQLRequestContext,
GraphQLRequest,
GraphQLResponse,
} from 'apollo-server-core/dist/requestPipelineAPI';
export {
GraphQLServiceContext,
GraphQLRequestContext,
GraphQLRequest,
GraphQLResponse,
};
type ValueOrPromise<T> = T | Promise<T>;
export interface ApolloServerPlugin {
serverWillStart?(service: GraphQLServiceContext): ValueOrPromise<void>;
requestDidStart?<TContext>(
requestContext: GraphQLRequestContext<TContext>,
): GraphQLRequestListener<TContext> | void;
}
export type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
export interface GraphQLRequestListener<TContext = Record<string, any>> {
parsingDidStart?(
requestContext: GraphQLRequestContext<TContext>,
): (err?: Error) => void | void;
validationDidStart?(
requestContext: WithRequired<GraphQLRequestContext<TContext>, 'document'>,
): (err?: ReadonlyArray<Error>) => void | void;
didResolveOperation?(
requestContext: WithRequired<
GraphQLRequestContext<TContext>,
'document' | 'operationName' | 'operation'
>,
): ValueOrPromise<void>;
executionDidStart?(
requestContext: WithRequired<
GraphQLRequestContext<TContext>,
'document' | 'operationName' | 'operation'
>,
): (err?: Error) => void | void;
willSendResponse?(
requestContext: WithRequired<GraphQLRequestContext<TContext>, 'response'>,
): ValueOrPromise<void>;
}