1 |
|
2 | import { EventEmitter } from 'events';
|
3 | import { GraphQLResolveInfo } from 'graphql';
|
4 | import { IDebugger } from '@cortexql/core';
|
5 | import { Request } from 'express';
|
6 | import * as WebSocket from 'ws';
|
7 | import { OperationMessage, ExecutionParams } from 'subscriptions-transport-ws';
|
8 | import { GraphQLSchema, DocumentNode, ExecutionResult } from 'graphql';
|
9 | export interface ContextExecute {
|
10 | (document: DocumentNode, variableValues?: {
|
11 | [key: string]: any;
|
12 | }, operationName?: string): Promise<ExecutionResult>;
|
13 | }
|
14 | export interface ContextSubscribe {
|
15 | (document: DocumentNode, variableValues?: {
|
16 | [key: string]: any;
|
17 | }, operationName?: string): Promise<ExecutionResult | AsyncIterator<ExecutionResult>>;
|
18 | }
|
19 | export interface ContextParams {
|
20 | [key: string]: any;
|
21 | }
|
22 | export declare function createContextId(context: BaseContext): any;
|
23 | export declare function createExecutionContextId(context: BaseContext, info?: GraphQLResolveInfo): any;
|
24 | export declare function createContextNamespace(context: BaseContext, info?: GraphQLResolveInfo, id?: any): string;
|
25 | export declare class BaseContext {
|
26 | params: ContextParams;
|
27 | operationName: string | undefined;
|
28 | operationType: string | undefined;
|
29 | id: any;
|
30 | schema: GraphQLSchema;
|
31 | event: EventEmitter;
|
32 | executionEvent?: EventEmitter;
|
33 | execute: ContextExecute;
|
34 | subscribe: ContextSubscribe;
|
35 | context?: this;
|
36 | completed: boolean;
|
37 | completionError?: Error;
|
38 | completionReason?: string;
|
39 | isExecution: false;
|
40 | destroy(handler: (...args: any[]) => void): EventEmitter;
|
41 | on(event: string, handler: (...args: any[]) => void): EventEmitter;
|
42 | once(event: string, handler: (...args: any[]) => void): EventEmitter;
|
43 | removeListener(event: string, handler: (...args: any[]) => void): EventEmitter;
|
44 | removeAllListeners(event: string): EventEmitter;
|
45 | emit(event: string, ...args: any[]): boolean;
|
46 | constructor(params: ContextParams, operationName?: string | undefined, operationType?: string | undefined, id?: any);
|
47 | debug: IDebugger;
|
48 | execution(info?: GraphQLResolveInfo): Promise<ExecutionContext<this>>;
|
49 | end(): void;
|
50 | end(error: Error | null, reason?: string): void;
|
51 | end(handler: (error?: Error | null, reason?: string) => void): Promise<void>;
|
52 | }
|
53 | export declare class BaseExecutionContext<T extends BaseContext> {
|
54 | context: T;
|
55 | info: GraphQLResolveInfo | undefined;
|
56 | executionEvent: EventEmitter;
|
57 | isExecution: boolean;
|
58 | id: any;
|
59 | debug: IDebugger;
|
60 | completed: boolean;
|
61 | completionError?: Error;
|
62 | completionReason?: string;
|
63 | constructor(context: T, info?: GraphQLResolveInfo | undefined);
|
64 | destroy(handler: (...args: any[]) => void): EventEmitter;
|
65 | on(event: string, handler: (...args: any[]) => void): EventEmitter;
|
66 | once(event: string, handler: (...args: any[]) => void): EventEmitter;
|
67 | removeListener(event: string, handler: (...args: any[]) => void): EventEmitter;
|
68 | removeAllListeners(event: string): EventEmitter;
|
69 | emit(event: string, ...args: any[]): boolean;
|
70 | end(): void;
|
71 | end(error: Error | null, reason?: string): void;
|
72 | end(handler: (error?: Error | null, reason?: string) => void): Promise<void>;
|
73 | }
|
74 | export declare type ExecutionContext<T extends BaseContext> = T & BaseExecutionContext<T>;
|
75 | export declare function createContext(params: ContextParams, operationName?: string, operationType?: string, executionId?: any): Promise<BaseContext>;
|
76 | export declare function createExecutionContext<T extends BaseContext>(context: T, info?: GraphQLResolveInfo): Promise<ExecutionContext<T>>;
|
77 | export declare function getOperationFromQuery(query: string): {
|
78 | operationName: string;
|
79 | operationType: string;
|
80 | } | {
|
81 | operationName: undefined;
|
82 | operationType: undefined;
|
83 | };
|
84 | export declare function createContextFromExpressRequest(req: Request, params?: ContextParams): Promise<BaseContext>;
|
85 | export declare function createContextFromWebSocketTransport(webSocket: WebSocket, message: OperationMessage, params: ExecutionParams): Promise<BaseContext>;
|