-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
connections.ts
63 lines (56 loc) · 1.55 KB
/
connections.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
export interface IConnection {
/**
* Unique connection id
*/
readonly id: string;
/**
* Extra connection data, this data is stored only upon registration
* All values should be JSON serializable
*/
readonly data: IConnectionData;
}
export interface IConnectionData {
[key: string]: any;
/**
* Connection context data provided from GQL_CONNECTION_INIT message or from onConnect method
* This data is passed to graphql resolvers' context
* All values should be JSON serializable
*/
context: Object;
/**
* Indicates whether connection sent GQL_CONNECTION_INIT message or
*/
readonly isInitialized: boolean;
}
export interface HydrateConnectionOptions {
/**
* How many times should we retry the connection query in case it fails for timing issues
*
* Default is 0
*/
retryCount?: number;
/**
* How long should we wait until we try determine connection state again?
*
* Default is 50ms
*/
timeout?: number;
}
export interface IConnectEvent {
connectionId: string;
endpoint: string;
}
export interface IConnectionManager {
hydrateConnection(
connectionId: string,
options?: HydrateConnectionOptions,
): Promise<IConnection>;
setConnectionData(data: Object, connection: IConnection): Promise<void>;
registerConnection(event: IConnectEvent): Promise<IConnection>;
sendToConnection(
connection: IConnection,
payload: string | Buffer,
): Promise<void>;
unregisterConnection(connection: IConnection): Promise<void>;
closeConnection(connection: IConnection): Promise<void>;
}