1 |
|
2 | import * as WebSocket from 'ws';
|
3 | import { ExecutionResult, GraphQLSchema, DocumentNode, ValidationContext, ExecutionArgs, SubscriptionArgs } from 'graphql';
|
4 | import { IncomingMessage } from 'http';
|
5 | export declare type ExecutionIterator = AsyncIterator<ExecutionResult>;
|
6 | export interface ExecutionParams<TContext = any> {
|
7 | query: string | DocumentNode;
|
8 | variables: {
|
9 | [key: string]: any;
|
10 | };
|
11 | operationName: string;
|
12 | context: TContext;
|
13 | formatResponse?: Function;
|
14 | formatError?: Function;
|
15 | callback?: Function;
|
16 | schema?: GraphQLSchema;
|
17 | }
|
18 | export declare type ConnectionContext = {
|
19 | initPromise?: Promise<any>;
|
20 | isLegacy: boolean;
|
21 | socket: WebSocket;
|
22 | request: IncomingMessage;
|
23 | operations: {
|
24 | [opId: string]: ExecutionIterator;
|
25 | };
|
26 | };
|
27 | export interface OperationMessagePayload {
|
28 | [key: string]: any;
|
29 | query?: string;
|
30 | variables?: {
|
31 | [key: string]: any;
|
32 | };
|
33 | operationName?: string;
|
34 | }
|
35 | export interface OperationMessage {
|
36 | payload?: OperationMessagePayload;
|
37 | id?: string;
|
38 | type: string;
|
39 | }
|
40 | export declare type ExecuteFunction = (args: ExecutionArgs) => ExecutionResult | Promise<ExecutionResult> | AsyncIterator<ExecutionResult>;
|
41 | export declare type SubscribeFunction = (args: SubscriptionArgs) => AsyncIterator<ExecutionResult> | Promise<AsyncIterator<ExecutionResult> | ExecutionResult>;
|
42 | export interface ServerOptions {
|
43 | rootValue?: any;
|
44 | schema?: GraphQLSchema;
|
45 | execute?: ExecuteFunction;
|
46 | subscribe?: SubscribeFunction;
|
47 | validationRules?: Array<(context: ValidationContext) => any> | ReadonlyArray<any>;
|
48 | onOperation?: Function;
|
49 | onOperationComplete?: Function;
|
50 | onConnect?: Function;
|
51 | onDisconnect?: Function;
|
52 | keepAlive?: number;
|
53 | }
|
54 | export declare class SubscriptionServer {
|
55 | private onOperation;
|
56 | private onOperationComplete;
|
57 | private onConnect;
|
58 | private onDisconnect;
|
59 | private wsServer;
|
60 | private execute;
|
61 | private subscribe;
|
62 | private schema;
|
63 | private rootValue;
|
64 | private keepAlive;
|
65 | private closeHandler;
|
66 | private specifiedRules;
|
67 | static create(options: ServerOptions, socketOptionsOrServer: WebSocket.ServerOptions | WebSocket.Server): SubscriptionServer;
|
68 | constructor(options: ServerOptions, socketOptionsOrServer: WebSocket.ServerOptions | WebSocket.Server);
|
69 | get server(): WebSocket.Server;
|
70 | close(): void;
|
71 | private loadExecutor;
|
72 | private unsubscribe;
|
73 | private onClose;
|
74 | private onMessage;
|
75 | private sendKeepAlive;
|
76 | private sendMessage;
|
77 | private sendError;
|
78 | }
|