@constructive-io/graphql-codegen 4.39.0 → 4.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,9 +9,38 @@
|
|
|
9
9
|
* Any changes here will affect all generated ORM clients.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
|
|
12
|
+
// Minimal type shims so this module compiles without graphql-ws
|
|
13
|
+
// installed. Consumers supply a WsClient via RealtimeConfig;
|
|
14
|
+
// the SDK itself never imports or requires graphql-ws.
|
|
15
|
+
|
|
16
|
+
interface WsGraphQLError {
|
|
17
|
+
readonly message: string;
|
|
18
|
+
readonly [key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface WsExecutionResult<TData = Record<string, unknown>> {
|
|
22
|
+
data?: TData | null;
|
|
23
|
+
errors?: readonly WsGraphQLError[];
|
|
24
|
+
extensions?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface WsSink<T> {
|
|
28
|
+
next(value: T): void;
|
|
29
|
+
error(error: unknown): void;
|
|
30
|
+
complete(): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Minimal interface matching the graphql-ws Client.
|
|
35
|
+
* Consumers pass a concrete instance via RealtimeConfig.client.
|
|
36
|
+
*/
|
|
37
|
+
export interface WsClient {
|
|
38
|
+
subscribe<TData = Record<string, unknown>>(
|
|
39
|
+
payload: { query: string; variables?: Record<string, unknown> },
|
|
40
|
+
sink: WsSink<WsExecutionResult<TData>>,
|
|
41
|
+
): () => void;
|
|
42
|
+
dispose(): void;
|
|
43
|
+
}
|
|
15
44
|
|
|
16
45
|
// ============================================================================
|
|
17
46
|
// Types
|
|
@@ -85,40 +114,32 @@ export interface SubscriptionFieldMeta {
|
|
|
85
114
|
/**
|
|
86
115
|
* Configuration for the realtime (WebSocket) connection.
|
|
87
116
|
* Pass this as the `realtime` option in OrmClientConfig.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* import { createClient } from 'graphql-ws';
|
|
121
|
+
*
|
|
122
|
+
* const client = createOrmClient({
|
|
123
|
+
* endpoint: 'https://api.example.com/graphql',
|
|
124
|
+
* realtime: {
|
|
125
|
+
* client: createClient({ url: 'wss://api.example.com/graphql' }),
|
|
126
|
+
* },
|
|
127
|
+
* });
|
|
128
|
+
* ```
|
|
88
129
|
*/
|
|
89
130
|
export interface RealtimeConfig {
|
|
90
|
-
/** WebSocket endpoint URL (e.g., 'wss://api.example.com/graphql') */
|
|
91
|
-
url: string;
|
|
92
|
-
/**
|
|
93
|
-
* Returns the current auth token. Called on connection init and
|
|
94
|
-
* on reconnection so the client always sends a fresh token.
|
|
95
|
-
*/
|
|
96
|
-
getToken?: () => string | Promise<string>;
|
|
97
131
|
/**
|
|
98
|
-
*
|
|
99
|
-
*
|
|
132
|
+
* A graphql-ws Client instance (or any object satisfying WsClient).
|
|
133
|
+
* The consumer creates this themselves, giving full control over
|
|
134
|
+
* connection options, auth, and transport.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { createClient } from 'graphql-ws';
|
|
139
|
+
* const wsClient = createClient({ url: 'wss://...' });
|
|
140
|
+
* ```
|
|
100
141
|
*/
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Whether to connect lazily (on first subscribe) or eagerly.
|
|
104
|
-
* @default true
|
|
105
|
-
*/
|
|
106
|
-
lazy?: boolean;
|
|
107
|
-
/**
|
|
108
|
-
* Maximum number of reconnection attempts before giving up.
|
|
109
|
-
* @default 5
|
|
110
|
-
*/
|
|
111
|
-
retryAttempts?: number;
|
|
112
|
-
/**
|
|
113
|
-
* Delay between reconnection attempts in milliseconds,
|
|
114
|
-
* or a function for custom backoff.
|
|
115
|
-
* @default 1000
|
|
116
|
-
*/
|
|
117
|
-
retryWait?: number | ((retryCount: number) => number | Promise<number>);
|
|
118
|
-
/** Called when the WebSocket connection is established */
|
|
119
|
-
onConnected?: () => void;
|
|
120
|
-
/** Called when the WebSocket connection is closed */
|
|
121
|
-
onDisconnected?: (reason?: unknown) => void;
|
|
142
|
+
client: WsClient;
|
|
122
143
|
}
|
|
123
144
|
|
|
124
145
|
// ============================================================================
|
|
@@ -126,8 +147,8 @@ export interface RealtimeConfig {
|
|
|
126
147
|
// ============================================================================
|
|
127
148
|
|
|
128
149
|
/**
|
|
129
|
-
* Manages a
|
|
130
|
-
* subscriptions over it. Created
|
|
150
|
+
* Manages a graphql-ws WebSocket client and multiplexes
|
|
151
|
+
* subscriptions over it. Created by OrmClient when `realtime`
|
|
131
152
|
* config is provided.
|
|
132
153
|
*/
|
|
133
154
|
export class RealtimeManager {
|
|
@@ -137,56 +158,7 @@ export class RealtimeManager {
|
|
|
137
158
|
private activeSubscriptions = 0;
|
|
138
159
|
|
|
139
160
|
constructor(config: RealtimeConfig) {
|
|
140
|
-
|
|
141
|
-
const { createClient: createWsClient } = require('graphql-ws') as typeof import('graphql-ws');
|
|
142
|
-
|
|
143
|
-
const retryWait = async (retryCount: number): Promise<void> => {
|
|
144
|
-
if (typeof config.retryWait === 'function') {
|
|
145
|
-
const result = config.retryWait(retryCount);
|
|
146
|
-
const ms = typeof result === 'number' ? result : await result;
|
|
147
|
-
await new Promise<void>((resolve) => setTimeout(resolve, ms));
|
|
148
|
-
} else {
|
|
149
|
-
const base =
|
|
150
|
-
typeof config.retryWait === 'number' ? config.retryWait : 1000;
|
|
151
|
-
await new Promise<void>((resolve) =>
|
|
152
|
-
setTimeout(resolve, base * Math.pow(2, retryCount)),
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
this.wsClient = createWsClient({
|
|
158
|
-
url: config.url,
|
|
159
|
-
lazy: config.lazy ?? true,
|
|
160
|
-
retryAttempts: config.retryAttempts ?? 5,
|
|
161
|
-
retryWait,
|
|
162
|
-
connectionParams: async () => {
|
|
163
|
-
const params: Record<string, unknown> = {
|
|
164
|
-
...config.connectionParams,
|
|
165
|
-
};
|
|
166
|
-
if (config.getToken) {
|
|
167
|
-
const token = await config.getToken();
|
|
168
|
-
params['authorization'] = `Bearer ${token}`;
|
|
169
|
-
}
|
|
170
|
-
return params;
|
|
171
|
-
},
|
|
172
|
-
on: {
|
|
173
|
-
connecting: () => {
|
|
174
|
-
const newState =
|
|
175
|
-
this.connectionState === 'disconnected'
|
|
176
|
-
? 'connecting'
|
|
177
|
-
: 'reconnecting';
|
|
178
|
-
this.setConnectionState(newState);
|
|
179
|
-
},
|
|
180
|
-
connected: () => {
|
|
181
|
-
this.setConnectionState('connected');
|
|
182
|
-
config.onConnected?.();
|
|
183
|
-
},
|
|
184
|
-
closed: (event) => {
|
|
185
|
-
this.setConnectionState('disconnected');
|
|
186
|
-
config.onDisconnected?.(event);
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
});
|
|
161
|
+
this.wsClient = config.client;
|
|
190
162
|
}
|
|
191
163
|
|
|
192
164
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@constructive-io/graphql-codegen",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.40.0",
|
|
4
4
|
"description": "GraphQL SDK generator for Constructive databases with React Query hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -56,24 +56,24 @@
|
|
|
56
56
|
"@0no-co/graphql.web": "^1.1.2",
|
|
57
57
|
"@babel/generator": "^7.29.1",
|
|
58
58
|
"@babel/types": "^7.29.0",
|
|
59
|
-
"@constructive-io/graphql-query": "^3.
|
|
60
|
-
"@constructive-io/graphql-types": "^3.
|
|
59
|
+
"@constructive-io/graphql-query": "^3.23.0",
|
|
60
|
+
"@constructive-io/graphql-types": "^3.9.0",
|
|
61
61
|
"@inquirerer/utils": "^3.3.5",
|
|
62
|
-
"@pgpmjs/core": "^6.
|
|
62
|
+
"@pgpmjs/core": "^6.17.0",
|
|
63
63
|
"ajv": "^8.18.0",
|
|
64
64
|
"deepmerge": "^4.3.1",
|
|
65
65
|
"find-and-require-package-json": "^0.9.1",
|
|
66
|
-
"gql-ast": "^3.
|
|
67
|
-
"graphile-schema": "^1.
|
|
66
|
+
"gql-ast": "^3.9.0",
|
|
67
|
+
"graphile-schema": "^1.19.0",
|
|
68
68
|
"graphql": "16.13.0",
|
|
69
69
|
"inflekt": "^0.7.1",
|
|
70
70
|
"inquirerer": "^4.7.0",
|
|
71
71
|
"jiti": "^2.6.1",
|
|
72
72
|
"oxfmt": "^0.42.0",
|
|
73
|
-
"pg-cache": "^3.
|
|
74
|
-
"pg-env": "^1.
|
|
75
|
-
"pgsql-client": "^3.
|
|
76
|
-
"pgsql-seed": "^2.
|
|
73
|
+
"pg-cache": "^3.9.0",
|
|
74
|
+
"pg-env": "^1.13.0",
|
|
75
|
+
"pgsql-client": "^3.13.0",
|
|
76
|
+
"pgsql-seed": "^2.13.0",
|
|
77
77
|
"undici": "^7.24.6"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
@@ -100,5 +100,5 @@
|
|
|
100
100
|
"tsx": "^4.21.0",
|
|
101
101
|
"typescript": "^5.9.3"
|
|
102
102
|
},
|
|
103
|
-
"gitHead": "
|
|
103
|
+
"gitHead": "c665e2443ec98da61e9f372cf663cb9973afef4b"
|
|
104
104
|
}
|