@graphql-hive/gateway 1.15.0-alpha-a2fe448e5ea2e6cf54b36f212b3eb5fee3167fb1 → 2.0.0-alpha-f3f43a13e2e907dc5acc4be8a23dc9870b2d6787
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.
- package/CHANGELOG.md +21 -11
- package/dist/bin.cjs +4 -4
- package/dist/bin.js +4 -4
- package/dist/{cli-Dts35ZPf.js → cli-BBlJHQNF.js} +74 -407
- package/dist/{cli-DeVzUuQb.cjs → cli-_WmSliwb.cjs} +72 -406
- package/dist/index.cjs +9 -11
- package/dist/index.d.cts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +3 -3
- package/package.json +13 -13
- package/dist/ESM_wrapper-B4cRuNGt.js +0 -126
- package/dist/ESM_wrapper-D0jQu0hQ.cjs +0 -168
@@ -3,10 +3,10 @@ import module from 'node:module';
|
|
3
3
|
import { availableParallelism, freemem, platform, release } from 'node:os';
|
4
4
|
import { join, isAbsolute, resolve } from 'node:path';
|
5
5
|
import { Option, Command, InvalidArgumentError } from '@commander-js/extra-typings';
|
6
|
-
import {
|
7
|
-
import {
|
8
|
-
import { getGraphQLWSOptions, handleLoggingConfig as handleLoggingConfig$1, createGatewayRuntime } from '@graphql-hive/gateway-runtime';
|
6
|
+
import { LegacyLogger, Logger } from '@graphql-hive/logger';
|
7
|
+
import { getGraphQLWSOptions, createLoggerFromLogging, createGatewayRuntime } from '@graphql-hive/gateway-runtime';
|
9
8
|
import { PubSub } from '@graphql-hive/pubsub';
|
9
|
+
import { registerTerminateHandler, isUrl } from '@graphql-mesh/utils';
|
10
10
|
import { lstat, watch } from 'node:fs/promises';
|
11
11
|
import { pathToFileURL } from 'node:url';
|
12
12
|
import { promises } from 'node:fs';
|
@@ -71,266 +71,6 @@ function parse(str = '', format = 'ms') {
|
|
71
71
|
return result && ((result / (parse.unit[format] || 1)) * (str[0] === '-' ? -1 : 1))
|
72
72
|
}
|
73
73
|
|
74
|
-
// Taken from graphql-js
|
75
|
-
// https://github.com/graphql/graphql-js/blob/main/src/jsutils/inspect.ts
|
76
|
-
const MAX_RECURSIVE_DEPTH = 3;
|
77
|
-
/**
|
78
|
-
* Used to print values in error messages.
|
79
|
-
*/
|
80
|
-
function inspect(value) {
|
81
|
-
return formatValue(value, []);
|
82
|
-
}
|
83
|
-
function formatValue(value, seenValues) {
|
84
|
-
switch (typeof value) {
|
85
|
-
case 'string':
|
86
|
-
return JSON.stringify(value);
|
87
|
-
case 'function':
|
88
|
-
return value.name ? `[function ${value.name}]` : '[function]';
|
89
|
-
case 'object':
|
90
|
-
return formatObjectValue(value, seenValues);
|
91
|
-
default:
|
92
|
-
return String(value);
|
93
|
-
}
|
94
|
-
}
|
95
|
-
function formatError(value) {
|
96
|
-
// eslint-disable-next-line no-constant-condition
|
97
|
-
if ((value.name = 'GraphQLError')) {
|
98
|
-
return value.toString();
|
99
|
-
}
|
100
|
-
return `${value.name}: ${value.message};\n ${value.stack}`;
|
101
|
-
}
|
102
|
-
function formatObjectValue(value, previouslySeenValues) {
|
103
|
-
if (value === null) {
|
104
|
-
return 'null';
|
105
|
-
}
|
106
|
-
if (value instanceof Error) {
|
107
|
-
if (value.name === 'AggregateError') {
|
108
|
-
return (formatError(value) +
|
109
|
-
'\n' +
|
110
|
-
formatArray(value.errors, previouslySeenValues));
|
111
|
-
}
|
112
|
-
return formatError(value);
|
113
|
-
}
|
114
|
-
if (previouslySeenValues.includes(value)) {
|
115
|
-
return '[Circular]';
|
116
|
-
}
|
117
|
-
const seenValues = [...previouslySeenValues, value];
|
118
|
-
if (isJSONable(value)) {
|
119
|
-
const jsonValue = value.toJSON();
|
120
|
-
// check for infinite recursion
|
121
|
-
if (jsonValue !== value) {
|
122
|
-
return typeof jsonValue === 'string' ? jsonValue : formatValue(jsonValue, seenValues);
|
123
|
-
}
|
124
|
-
}
|
125
|
-
else if (Array.isArray(value)) {
|
126
|
-
return formatArray(value, seenValues);
|
127
|
-
}
|
128
|
-
return formatObject(value, seenValues);
|
129
|
-
}
|
130
|
-
function isJSONable(value) {
|
131
|
-
return typeof value.toJSON === 'function';
|
132
|
-
}
|
133
|
-
function formatObject(object, seenValues) {
|
134
|
-
const entries = Object.entries(object);
|
135
|
-
if (entries.length === 0) {
|
136
|
-
return '{}';
|
137
|
-
}
|
138
|
-
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
139
|
-
return '[' + getObjectTag(object) + ']';
|
140
|
-
}
|
141
|
-
const properties = entries.map(([key, value]) => key + ': ' + formatValue(value, seenValues));
|
142
|
-
return '{ ' + properties.join(', ') + ' }';
|
143
|
-
}
|
144
|
-
function formatArray(array, seenValues) {
|
145
|
-
if (array.length === 0) {
|
146
|
-
return '[]';
|
147
|
-
}
|
148
|
-
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
149
|
-
return '[Array]';
|
150
|
-
}
|
151
|
-
const len = array.length;
|
152
|
-
const items = [];
|
153
|
-
for (let i = 0; i < len; ++i) {
|
154
|
-
items.push(formatValue(array[i], seenValues));
|
155
|
-
}
|
156
|
-
return '[' + items.join(', ') + ']';
|
157
|
-
}
|
158
|
-
function getObjectTag(object) {
|
159
|
-
const tag = Object.prototype.toString
|
160
|
-
.call(object)
|
161
|
-
.replace(/^\[object /, '')
|
162
|
-
.replace(/]$/, '');
|
163
|
-
if (tag === 'Object' && typeof object.constructor === 'function') {
|
164
|
-
const name = object.constructor.name;
|
165
|
-
if (typeof name === 'string' && name !== '') {
|
166
|
-
return name;
|
167
|
-
}
|
168
|
-
}
|
169
|
-
return tag;
|
170
|
-
}
|
171
|
-
|
172
|
-
function truthy(val) {
|
173
|
-
return val === true || val === 1 || ["1", "t", "true", "y", "yes"].includes(String(val));
|
174
|
-
}
|
175
|
-
class JSONLogger {
|
176
|
-
name;
|
177
|
-
meta;
|
178
|
-
logLevel;
|
179
|
-
console;
|
180
|
-
constructor(opts) {
|
181
|
-
this.name = opts?.name;
|
182
|
-
this.console = opts?.console || console;
|
183
|
-
this.meta = opts?.meta || {};
|
184
|
-
const debugStrs = [process$1.env["DEBUG"], globalThis.DEBUG];
|
185
|
-
if (opts?.level != null) {
|
186
|
-
this.logLevel = opts.level;
|
187
|
-
} else {
|
188
|
-
this.logLevel = LogLevel.info;
|
189
|
-
for (const debugStr of debugStrs) {
|
190
|
-
if (debugStr) {
|
191
|
-
if (truthy(debugStr)) {
|
192
|
-
this.logLevel = LogLevel.debug;
|
193
|
-
break;
|
194
|
-
}
|
195
|
-
if (opts?.name) {
|
196
|
-
if (debugStr?.toString()?.includes(opts.name)) {
|
197
|
-
this.logLevel = LogLevel.debug;
|
198
|
-
break;
|
199
|
-
}
|
200
|
-
}
|
201
|
-
}
|
202
|
-
}
|
203
|
-
}
|
204
|
-
}
|
205
|
-
log(...messageArgs) {
|
206
|
-
if (this.logLevel > LogLevel.info) {
|
207
|
-
return;
|
208
|
-
}
|
209
|
-
const finalMessage = this.prepareFinalMessage("info", messageArgs);
|
210
|
-
this.console.log(finalMessage);
|
211
|
-
}
|
212
|
-
warn(...messageArgs) {
|
213
|
-
if (this.logLevel > LogLevel.warn) {
|
214
|
-
return;
|
215
|
-
}
|
216
|
-
const finalMessage = this.prepareFinalMessage("warn", messageArgs);
|
217
|
-
this.console.warn(finalMessage);
|
218
|
-
}
|
219
|
-
info(...messageArgs) {
|
220
|
-
if (this.logLevel > LogLevel.info) {
|
221
|
-
return;
|
222
|
-
}
|
223
|
-
const finalMessage = this.prepareFinalMessage("info", messageArgs);
|
224
|
-
this.console.info(finalMessage);
|
225
|
-
}
|
226
|
-
error(...messageArgs) {
|
227
|
-
if (this.logLevel > LogLevel.error) {
|
228
|
-
return;
|
229
|
-
}
|
230
|
-
const finalMessage = this.prepareFinalMessage("error", messageArgs);
|
231
|
-
this.console.error(finalMessage);
|
232
|
-
}
|
233
|
-
debug(...messageArgs) {
|
234
|
-
if (this.logLevel > LogLevel.debug) {
|
235
|
-
return;
|
236
|
-
}
|
237
|
-
const finalMessage = this.prepareFinalMessage("debug", messageArgs);
|
238
|
-
this.console.debug(finalMessage);
|
239
|
-
}
|
240
|
-
child(nameOrMeta) {
|
241
|
-
let newName;
|
242
|
-
let newMeta;
|
243
|
-
if (typeof nameOrMeta === "string") {
|
244
|
-
newName = this.name ? `${this.name}, ${nameOrMeta}` : nameOrMeta;
|
245
|
-
newMeta = this.meta;
|
246
|
-
} else if (typeof nameOrMeta === "object") {
|
247
|
-
newName = this.name;
|
248
|
-
newMeta = { ...this.meta, ...nameOrMeta };
|
249
|
-
} else {
|
250
|
-
throw new Error("Invalid argument type");
|
251
|
-
}
|
252
|
-
return new JSONLogger({
|
253
|
-
name: newName,
|
254
|
-
meta: newMeta,
|
255
|
-
level: this.logLevel,
|
256
|
-
console: this.console
|
257
|
-
});
|
258
|
-
}
|
259
|
-
addPrefix(prefix) {
|
260
|
-
if (typeof prefix === "string") {
|
261
|
-
this.name = this.name ? `${this.name}, ${prefix}` : prefix;
|
262
|
-
} else if (typeof prefix === "object") {
|
263
|
-
this.meta = { ...this.meta, ...prefix };
|
264
|
-
}
|
265
|
-
return this;
|
266
|
-
}
|
267
|
-
prepareFinalMessage(level, messageArgs) {
|
268
|
-
const flattenedMessageArgs = messageArgs.flat(Infinity).flatMap((messageArg) => {
|
269
|
-
if (typeof messageArg === "function") {
|
270
|
-
messageArg = messageArg();
|
271
|
-
}
|
272
|
-
if (messageArg?.toJSON) {
|
273
|
-
messageArg = messageArg.toJSON();
|
274
|
-
}
|
275
|
-
if (messageArg instanceof AggregateError) {
|
276
|
-
return messageArg.errors;
|
277
|
-
}
|
278
|
-
return messageArg;
|
279
|
-
});
|
280
|
-
const finalMessage = {
|
281
|
-
...this.meta,
|
282
|
-
level,
|
283
|
-
time: (/* @__PURE__ */ new Date()).toISOString()
|
284
|
-
};
|
285
|
-
if (this.name) {
|
286
|
-
finalMessage["name"] = this.name;
|
287
|
-
}
|
288
|
-
const extras = [];
|
289
|
-
for (let messageArg of flattenedMessageArgs) {
|
290
|
-
if (messageArg == null) {
|
291
|
-
continue;
|
292
|
-
}
|
293
|
-
const typeofMessageArg = typeof messageArg;
|
294
|
-
if (typeofMessageArg === "string" || typeofMessageArg === "number" || typeofMessageArg === "boolean") {
|
295
|
-
finalMessage["msg"] = finalMessage["msg"] ? finalMessage["msg"] + ", " + messageArg : messageArg;
|
296
|
-
} else if (typeofMessageArg === "object") {
|
297
|
-
if (messageArg instanceof Error) {
|
298
|
-
finalMessage["msg"] = finalMessage["msg"] ? finalMessage["msg"] + ", " + messageArg.message : messageArg.message;
|
299
|
-
finalMessage["stack"] = messageArg.stack;
|
300
|
-
} else if (Object.prototype.toString.call(messageArg).startsWith("[object")) {
|
301
|
-
Object.assign(finalMessage, messageArg);
|
302
|
-
} else {
|
303
|
-
extras.push(messageArg);
|
304
|
-
}
|
305
|
-
}
|
306
|
-
}
|
307
|
-
if (extras.length) {
|
308
|
-
if (extras.length === 1) {
|
309
|
-
finalMessage["extras"] = inspect(extras[0]);
|
310
|
-
} else {
|
311
|
-
finalMessage["extras"] = extras.map((extra) => inspect(extra));
|
312
|
-
}
|
313
|
-
}
|
314
|
-
return JSON.stringify(finalMessage);
|
315
|
-
}
|
316
|
-
}
|
317
|
-
|
318
|
-
function getDefaultLogger(opts) {
|
319
|
-
const logFormat = process$1.env["LOG_FORMAT"] || globalThis.LOG_FORMAT;
|
320
|
-
if (logFormat) {
|
321
|
-
if (logFormat.toLowerCase() === "json") {
|
322
|
-
return new JSONLogger(opts);
|
323
|
-
} else if (logFormat.toLowerCase() === "pretty") {
|
324
|
-
return new DefaultLogger(opts?.name, opts?.level);
|
325
|
-
}
|
326
|
-
}
|
327
|
-
const nodeEnv = process$1.env["NODE_ENV"] || globalThis.NODE_ENV;
|
328
|
-
if (nodeEnv === "production") {
|
329
|
-
return new JSONLogger(opts);
|
330
|
-
}
|
331
|
-
return new DefaultLogger(opts?.name, opts?.level);
|
332
|
-
}
|
333
|
-
|
334
74
|
const defaultConfigExtensions = [
|
335
75
|
".ts",
|
336
76
|
".mts",
|
@@ -404,12 +144,7 @@ async function getBuiltinPluginsFromConfig(config, ctx) {
|
|
404
144
|
}
|
405
145
|
if (config.openTelemetry) {
|
406
146
|
const { useOpenTelemetry } = await import('@graphql-mesh/plugin-opentelemetry');
|
407
|
-
plugins.push(
|
408
|
-
useOpenTelemetry({
|
409
|
-
logger: ctx.logger,
|
410
|
-
...config.openTelemetry
|
411
|
-
})
|
412
|
-
);
|
147
|
+
plugins.push(useOpenTelemetry({ ...config.openTelemetry, log: ctx.log }));
|
413
148
|
}
|
414
149
|
if (config.rateLimiting) {
|
415
150
|
const { default: useMeshRateLimit } = await import('@graphql-mesh/plugin-rate-limit');
|
@@ -468,7 +203,9 @@ async function getCacheInstanceFromConfig(config, ctx) {
|
|
468
203
|
const { default: RedisCache } = await import('@graphql-mesh/cache-redis');
|
469
204
|
return new RedisCache({
|
470
205
|
...ctx,
|
471
|
-
...config.cache
|
206
|
+
...config.cache,
|
207
|
+
// TODO: use new logger
|
208
|
+
logger: LegacyLogger.from(ctx.log)
|
472
209
|
});
|
473
210
|
}
|
474
211
|
case "cfw-kv": {
|
@@ -487,7 +224,7 @@ async function getCacheInstanceFromConfig(config, ctx) {
|
|
487
224
|
}
|
488
225
|
}
|
489
226
|
if (config.cache.type !== "localforage") {
|
490
|
-
ctx.
|
227
|
+
ctx.log.warn(
|
491
228
|
"Unknown cache type, falling back to localforage",
|
492
229
|
config.cache
|
493
230
|
);
|
@@ -554,7 +291,7 @@ async function startBunServer(gwRuntime, opts) {
|
|
554
291
|
};
|
555
292
|
}
|
556
293
|
const server = Bun.serve(serverOptions);
|
557
|
-
opts.log.info(
|
294
|
+
opts.log.info("Listening on %s", server.url);
|
558
295
|
gwRuntime.disposableStack.use(server);
|
559
296
|
}
|
560
297
|
|
@@ -621,7 +358,7 @@ async function startNodeHttpServer(gwRuntime, opts) {
|
|
621
358
|
);
|
622
359
|
}
|
623
360
|
const url = `${protocol}://${host}:${port}`.replace("0.0.0.0", "localhost");
|
624
|
-
log.debug(
|
361
|
+
log.debug("Starting server on %s", url);
|
625
362
|
if (!disableWebsockets) {
|
626
363
|
log.debug("Setting up WebSocket server");
|
627
364
|
const { WebSocketServer } = await import('ws');
|
@@ -639,12 +376,12 @@ async function startNodeHttpServer(gwRuntime, opts) {
|
|
639
376
|
);
|
640
377
|
gwRuntime.disposableStack.defer(
|
641
378
|
() => new Promise((resolve, reject) => {
|
642
|
-
log.info(
|
379
|
+
log.info("Stopping the WebSocket server");
|
643
380
|
wsServer.close((err) => {
|
644
381
|
if (err) {
|
645
382
|
return reject(err);
|
646
383
|
}
|
647
|
-
log.info(
|
384
|
+
log.info("Stopped the WebSocket server successfully");
|
648
385
|
return resolve();
|
649
386
|
});
|
650
387
|
})
|
@@ -653,14 +390,14 @@ async function startNodeHttpServer(gwRuntime, opts) {
|
|
653
390
|
return new Promise((resolve, reject) => {
|
654
391
|
server.once("error", reject);
|
655
392
|
server.listen(port, host, () => {
|
656
|
-
log.info(
|
393
|
+
log.info("Listening on %s", url);
|
657
394
|
gwRuntime.disposableStack.defer(
|
658
395
|
() => new Promise((resolve2) => {
|
659
396
|
process.stderr.write("\n");
|
660
|
-
log.info(
|
397
|
+
log.info("Stopping the server");
|
661
398
|
server.closeAllConnections();
|
662
399
|
server.close(() => {
|
663
|
-
log.info(
|
400
|
+
log.info("Stopped the server successfully");
|
664
401
|
return resolve2();
|
665
402
|
});
|
666
403
|
})
|
@@ -670,68 +407,7 @@ async function startNodeHttpServer(gwRuntime, opts) {
|
|
670
407
|
});
|
671
408
|
}
|
672
409
|
|
673
|
-
function
|
674
|
-
return async function startUwsServer(gwRuntime, opts) {
|
675
|
-
const {
|
676
|
-
log,
|
677
|
-
host = defaultOptions.host,
|
678
|
-
port = defaultOptions.port,
|
679
|
-
sslCredentials,
|
680
|
-
maxHeaderSize,
|
681
|
-
disableWebsockets
|
682
|
-
} = opts;
|
683
|
-
if (maxHeaderSize) {
|
684
|
-
process.env["UWS_HTTP_MAX_HEADER_SIZE"] = maxHeaderSize.toString();
|
685
|
-
}
|
686
|
-
let app;
|
687
|
-
let protocol;
|
688
|
-
if (sslCredentials) {
|
689
|
-
protocol = "https";
|
690
|
-
app = uws.SSLApp({
|
691
|
-
key_file_name: sslCredentials.key_file_name,
|
692
|
-
cert_file_name: sslCredentials.cert_file_name,
|
693
|
-
ca_file_name: sslCredentials.ca_file_name,
|
694
|
-
passphrase: sslCredentials.passphrase,
|
695
|
-
dh_params_file_name: sslCredentials.dh_params_file_name,
|
696
|
-
ssl_ciphers: sslCredentials.ssl_ciphers,
|
697
|
-
ssl_prefer_low_memory_usage: sslCredentials.ssl_prefer_low_memory_usage
|
698
|
-
});
|
699
|
-
} else {
|
700
|
-
protocol = "http";
|
701
|
-
app = uws.App();
|
702
|
-
}
|
703
|
-
const url = `${protocol}://${host}:${port}`.replace("0.0.0.0", "localhost");
|
704
|
-
log.debug(`Starting server on ${url}`);
|
705
|
-
if (!disableWebsockets) {
|
706
|
-
log.debug("Setting up WebSocket server");
|
707
|
-
const { makeBehavior } = await import('graphql-ws/use/uWebSockets');
|
708
|
-
const wsBehavior = makeBehavior(
|
709
|
-
getGraphQLWSOptions(gwRuntime, (ctx) => ({
|
710
|
-
req: ctx.extra?.persistedRequest,
|
711
|
-
socket: ctx.extra?.socket
|
712
|
-
}))
|
713
|
-
);
|
714
|
-
app.ws(gwRuntime.graphqlEndpoint, wsBehavior);
|
715
|
-
}
|
716
|
-
app.any("/*", gwRuntime);
|
717
|
-
return new Promise((resolve, reject) => {
|
718
|
-
app.listen(host, port, (listenSocket) => {
|
719
|
-
if (listenSocket) {
|
720
|
-
log.info(`Listening on ${url}`);
|
721
|
-
} else {
|
722
|
-
reject(new Error(`Failed to start server on ${url}`));
|
723
|
-
}
|
724
|
-
});
|
725
|
-
gwRuntime.disposableStack.defer(() => {
|
726
|
-
log.info(`Stopping the server`);
|
727
|
-
app.close();
|
728
|
-
resolve();
|
729
|
-
});
|
730
|
-
});
|
731
|
-
};
|
732
|
-
}
|
733
|
-
|
734
|
-
async function startServerForRuntime(runtime, {
|
410
|
+
function startServerForRuntime(runtime, {
|
735
411
|
log,
|
736
412
|
host = defaultOptions.host,
|
737
413
|
port = defaultOptions.port,
|
@@ -741,7 +417,7 @@ async function startServerForRuntime(runtime, {
|
|
741
417
|
}) {
|
742
418
|
process.on("message", (message) => {
|
743
419
|
if (message === "invalidateUnifiedGraph") {
|
744
|
-
log.info(
|
420
|
+
log.info("Invalidating Supergraph");
|
745
421
|
runtime.invalidateUnifiedGraph();
|
746
422
|
}
|
747
423
|
});
|
@@ -753,18 +429,7 @@ async function startServerForRuntime(runtime, {
|
|
753
429
|
disableWebsockets,
|
754
430
|
...sslCredentials ? { sslCredentials } : {}
|
755
431
|
};
|
756
|
-
|
757
|
-
if (globalThis.Bun) {
|
758
|
-
startServer = startBunServer;
|
759
|
-
} else {
|
760
|
-
try {
|
761
|
-
const uws = await import('./ESM_wrapper-B4cRuNGt.js');
|
762
|
-
log.info("uWebSockets.js is available, using it for the server");
|
763
|
-
startServer = createUWSStartFn(uws);
|
764
|
-
} catch {
|
765
|
-
startServer = startNodeHttpServer;
|
766
|
-
}
|
767
|
-
}
|
432
|
+
const startServer = globalThis.Bun ? startBunServer : startNodeHttpServer;
|
768
433
|
return startServer(runtime, serverOpts);
|
769
434
|
}
|
770
435
|
|
@@ -773,7 +438,7 @@ function handleFork(log, config) {
|
|
773
438
|
if (cluster.isPrimary && config.fork && config.fork > 1) {
|
774
439
|
const workers = /* @__PURE__ */ new Set();
|
775
440
|
let expectedToExit = false;
|
776
|
-
log.debug(
|
441
|
+
log.debug("Forking %d workers", config.fork);
|
777
442
|
for (let i = 0; i < config.fork; i++) {
|
778
443
|
const worker = cluster.fork();
|
779
444
|
const workerLogger = log.child({ worker: worker.id });
|
@@ -785,25 +450,23 @@ function handleFork(log, config) {
|
|
785
450
|
logData["code"] = code;
|
786
451
|
}
|
787
452
|
if (expectedToExit) {
|
788
|
-
workerLogger.debug("exited"
|
453
|
+
workerLogger.debug(logData, "exited");
|
789
454
|
} else {
|
790
455
|
workerLogger.error(
|
791
|
-
|
792
|
-
|
456
|
+
logData,
|
457
|
+
"Exited unexpectedly. A restart is recommended to ensure the stability of the service"
|
793
458
|
);
|
794
459
|
}
|
795
460
|
workers.delete(worker);
|
796
461
|
if (!expectedToExit && workers.size === 0) {
|
797
|
-
log.error(
|
462
|
+
log.error(logData, "All workers exited unexpectedly. Exiting...");
|
798
463
|
process.exit(1);
|
799
464
|
}
|
800
465
|
});
|
801
466
|
workers.add(worker);
|
802
467
|
}
|
803
468
|
registerTerminateHandler((signal) => {
|
804
|
-
log.info("Killing workers",
|
805
|
-
signal
|
806
|
-
});
|
469
|
+
log.info("Killing workers on %s", signal);
|
807
470
|
expectedToExit = true;
|
808
471
|
workers.forEach((w) => {
|
809
472
|
w.kill(signal);
|
@@ -812,15 +475,15 @@ function handleFork(log, config) {
|
|
812
475
|
return true;
|
813
476
|
}
|
814
477
|
} catch (e) {
|
815
|
-
log.error(
|
478
|
+
log.error(
|
479
|
+
// @ts-expect-error very likely an instanceof error
|
480
|
+
e,
|
481
|
+
"Error while forking workers"
|
482
|
+
);
|
816
483
|
}
|
817
484
|
return false;
|
818
485
|
}
|
819
486
|
|
820
|
-
function handleLoggingConfig(loggingConfig, ctx) {
|
821
|
-
ctx.log = handleLoggingConfig$1(loggingConfig, ctx.log);
|
822
|
-
}
|
823
|
-
|
824
487
|
function handleReportingConfig(ctx, loadedConfig, cliOpts) {
|
825
488
|
const confOpts = {
|
826
489
|
...loadedConfig.reporting?.type === "hive" ? {
|
@@ -836,34 +499,34 @@ function handleReportingConfig(ctx, loadedConfig, cliOpts) {
|
|
836
499
|
const opts = { ...confOpts, ...cliOpts };
|
837
500
|
if (cliOpts.hiveRegistryToken && cliOpts.hiveUsageAccessToken) {
|
838
501
|
ctx.log.error(
|
839
|
-
|
502
|
+
'Cannot use "--hive-registry-token" with "--hive-usage-access-token". Please use "--hive-usage-target" and "--hive-usage-access-token" or the config instead.'
|
840
503
|
);
|
841
504
|
process.exit(1);
|
842
505
|
}
|
843
506
|
if (cliOpts.hiveRegistryToken && opts.hiveUsageTarget) {
|
844
507
|
ctx.log.error(
|
845
|
-
|
508
|
+
'Cannot use "--hive-registry-token" with a target. Please use "--hive-usage-target" and "--hive-usage-access-token" or the config instead.'
|
846
509
|
);
|
847
510
|
process.exit(1);
|
848
511
|
}
|
849
512
|
if (opts.hiveUsageTarget && !opts.hiveUsageAccessToken) {
|
850
513
|
ctx.log.error(
|
851
|
-
|
514
|
+
'Hive usage target needs an access token. Please provide it through the "--hive-usage-access-token <token>" option or the config.'
|
852
515
|
);
|
853
516
|
process.exit(1);
|
854
517
|
}
|
855
518
|
if (opts.hiveUsageAccessToken && !opts.hiveUsageTarget) {
|
856
519
|
ctx.log.error(
|
857
|
-
|
520
|
+
'Hive usage access token needs a target. Please provide it through the "--hive-usage-target <target>" option or the config.'
|
858
521
|
);
|
859
522
|
process.exit(1);
|
860
523
|
}
|
861
524
|
const hiveUsageAccessToken = opts.hiveUsageAccessToken || opts.hiveRegistryToken;
|
862
525
|
if (hiveUsageAccessToken) {
|
863
526
|
if (opts.hiveUsageTarget) {
|
864
|
-
ctx.log.info(
|
527
|
+
ctx.log.info("Configuring Hive usage reporting");
|
865
528
|
} else {
|
866
|
-
ctx.log.info(
|
529
|
+
ctx.log.info("Configuring Hive registry reporting");
|
867
530
|
}
|
868
531
|
return {
|
869
532
|
...loadedConfig.reporting,
|
@@ -873,7 +536,7 @@ function handleReportingConfig(ctx, loadedConfig, cliOpts) {
|
|
873
536
|
};
|
874
537
|
}
|
875
538
|
if (opts.apolloKey) {
|
876
|
-
ctx.log.info(
|
539
|
+
ctx.log.info("Configuring Apollo GraphOS registry reporting");
|
877
540
|
if (!opts.apolloGraphRef?.includes("@")) {
|
878
541
|
ctx.log.error(
|
879
542
|
`Apollo GraphOS requires a graph ref in the format <graph-id>@<graph-variant>. Please provide a valid graph ref ${opts.apolloGraphRef ? `not ${opts.apolloGraphRef}` : ""}.`
|
@@ -930,11 +593,10 @@ const addCommand$2 = (ctx, cli) => cli.command("proxy").description(
|
|
930
593
|
// TODO: take schema from optsWithGlobals once https://github.com/commander-js/extra-typings/pull/76 is merged
|
931
594
|
this.opts().schema || hiveCdnEndpoint
|
932
595
|
);
|
933
|
-
const hiveCdnLogger = ctx.log.child({ source: "Hive CDN" });
|
934
596
|
if (hiveCdnEndpointOpt) {
|
935
597
|
if (hiveCdnKey) {
|
936
598
|
if (!isUrl(hiveCdnEndpointOpt)) {
|
937
|
-
|
599
|
+
ctx.log.error(
|
938
600
|
"Endpoint must be a URL when providing --hive-cdn-key but got " + hiveCdnEndpointOpt
|
939
601
|
);
|
940
602
|
process.exit(1);
|
@@ -973,11 +635,11 @@ const addCommand$2 = (ctx, cli) => cli.command("proxy").description(
|
|
973
635
|
const pubsub = loadedConfig.pubsub || new PubSub();
|
974
636
|
const cwd = loadedConfig.cwd || process.cwd();
|
975
637
|
if (loadedConfig.logging != null) {
|
976
|
-
|
638
|
+
ctx.log = createLoggerFromLogging(loadedConfig.logging);
|
977
639
|
}
|
978
640
|
const cache = await getCacheInstanceFromConfig(loadedConfig, {
|
979
641
|
pubsub,
|
980
|
-
|
642
|
+
log: ctx.log,
|
981
643
|
cwd
|
982
644
|
});
|
983
645
|
const builtinPlugins = await getBuiltinPluginsFromConfig(
|
@@ -986,7 +648,7 @@ const addCommand$2 = (ctx, cli) => cli.command("proxy").description(
|
|
986
648
|
...opts
|
987
649
|
},
|
988
650
|
{
|
989
|
-
|
651
|
+
log: ctx.log,
|
990
652
|
cache}
|
991
653
|
);
|
992
654
|
const config = {
|
@@ -1091,11 +753,11 @@ const addCommand$1 = (ctx, cli) => cli.command("subgraph").description(
|
|
1091
753
|
const pubsub = loadedConfig.pubsub || new PubSub();
|
1092
754
|
const cwd = loadedConfig.cwd || process.cwd();
|
1093
755
|
if (loadedConfig.logging != null) {
|
1094
|
-
|
756
|
+
ctx.log = createLoggerFromLogging(loadedConfig.logging);
|
1095
757
|
}
|
1096
758
|
const cache = await getCacheInstanceFromConfig(loadedConfig, {
|
1097
759
|
pubsub,
|
1098
|
-
|
760
|
+
log: ctx.log,
|
1099
761
|
cwd
|
1100
762
|
});
|
1101
763
|
const builtinPlugins = await getBuiltinPluginsFromConfig(
|
@@ -1104,7 +766,7 @@ const addCommand$1 = (ctx, cli) => cli.command("subgraph").description(
|
|
1104
766
|
...opts
|
1105
767
|
},
|
1106
768
|
{
|
1107
|
-
|
769
|
+
log: ctx.log,
|
1108
770
|
cache}
|
1109
771
|
);
|
1110
772
|
const config = {
|
@@ -1215,12 +877,13 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1215
877
|
});
|
1216
878
|
let supergraph2 = "supergraph.graphql";
|
1217
879
|
if (schemaPathOrUrl) {
|
1218
|
-
ctx.log.info(
|
880
|
+
ctx.log.info("Supergraph will be loaded from %s", schemaPathOrUrl);
|
1219
881
|
if (hiveCdnKey) {
|
1220
|
-
ctx.log.info(
|
882
|
+
ctx.log.info("Using Hive CDN key");
|
1221
883
|
if (!isUrl(schemaPathOrUrl)) {
|
1222
884
|
ctx.log.error(
|
1223
|
-
"Hive CDN endpoint must be a URL when providing --hive-cdn-key but got "
|
885
|
+
"Hive CDN endpoint must be a URL when providing --hive-cdn-key but got %s",
|
886
|
+
schemaPathOrUrl
|
1224
887
|
);
|
1225
888
|
process.exit(1);
|
1226
889
|
}
|
@@ -1230,10 +893,11 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1230
893
|
key: hiveCdnKey
|
1231
894
|
};
|
1232
895
|
} else if (apolloKey) {
|
1233
|
-
ctx.log.info(
|
896
|
+
ctx.log.info("Using GraphOS API key");
|
1234
897
|
if (!schemaPathOrUrl.includes("@")) {
|
1235
898
|
ctx.log.error(
|
1236
|
-
`Apollo GraphOS requires a graph ref in the format <graph-id>@<graph-variant> when providing --apollo-key. Please provide a valid graph ref not
|
899
|
+
`Apollo GraphOS requires a graph ref in the format <graph-id>@<graph-variant> when providing --apollo-key. Please provide a valid graph ref not %s.`,
|
900
|
+
schemaPathOrUrl
|
1237
901
|
);
|
1238
902
|
process.exit(1);
|
1239
903
|
}
|
@@ -1259,7 +923,7 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1259
923
|
);
|
1260
924
|
process.exit(1);
|
1261
925
|
}
|
1262
|
-
ctx.log.info(
|
926
|
+
ctx.log.info("Using Hive CDN endpoint %s", hiveCdnEndpoint);
|
1263
927
|
supergraph2 = {
|
1264
928
|
type: "hive",
|
1265
929
|
endpoint: hiveCdnEndpoint,
|
@@ -1268,17 +932,18 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1268
932
|
} else if (apolloGraphRef) {
|
1269
933
|
if (!apolloGraphRef.includes("@")) {
|
1270
934
|
ctx.log.error(
|
1271
|
-
|
935
|
+
"Apollo GraphOS requires a graph ref in the format <graph-id>@<graph-variant>. Please provide a valid graph ref not %s.",
|
936
|
+
apolloGraphRef
|
1272
937
|
);
|
1273
938
|
process.exit(1);
|
1274
939
|
}
|
1275
940
|
if (!apolloKey) {
|
1276
941
|
ctx.log.error(
|
1277
|
-
|
942
|
+
"Apollo GraphOS requires an API key. Please provide an API key using the --apollo-key option."
|
1278
943
|
);
|
1279
944
|
process.exit(1);
|
1280
945
|
}
|
1281
|
-
ctx.log.info(
|
946
|
+
ctx.log.info("Using Apollo Graph Ref %s", apolloGraphRef);
|
1282
947
|
supergraph2 = {
|
1283
948
|
type: "graphos",
|
1284
949
|
apiKey: apolloKey,
|
@@ -1288,7 +953,7 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1288
953
|
} else if ("supergraph" in loadedConfig) {
|
1289
954
|
supergraph2 = loadedConfig.supergraph;
|
1290
955
|
} else {
|
1291
|
-
ctx.log.info(
|
956
|
+
ctx.log.info("Using default supergraph location %s", supergraph2);
|
1292
957
|
}
|
1293
958
|
const registryConfig = {};
|
1294
959
|
const reporting = handleReportingConfig(ctx, loadedConfig, {
|
@@ -1304,11 +969,11 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1304
969
|
const pubsub = loadedConfig.pubsub || new PubSub();
|
1305
970
|
const cwd = loadedConfig.cwd || process.cwd();
|
1306
971
|
if (loadedConfig.logging != null) {
|
1307
|
-
|
972
|
+
ctx.log = createLoggerFromLogging(loadedConfig.logging);
|
1308
973
|
}
|
1309
974
|
const cache = await getCacheInstanceFromConfig(loadedConfig, {
|
1310
975
|
pubsub,
|
1311
|
-
|
976
|
+
log: ctx.log,
|
1312
977
|
cwd
|
1313
978
|
});
|
1314
979
|
const builtinPlugins = await getBuiltinPluginsFromConfig(
|
@@ -1317,7 +982,7 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1317
982
|
...opts
|
1318
983
|
},
|
1319
984
|
{
|
1320
|
-
|
985
|
+
log: ctx.log,
|
1321
986
|
cache}
|
1322
987
|
);
|
1323
988
|
const config = {
|
@@ -1344,7 +1009,7 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1344
1009
|
const token = hivePersistedDocumentsToken || loadedConfig.persistedDocuments && "token" in loadedConfig.persistedDocuments && loadedConfig.persistedDocuments.token;
|
1345
1010
|
if (!token) {
|
1346
1011
|
ctx.log.error(
|
1347
|
-
|
1012
|
+
'Hive persisted documents needs a CDN token. Please provide it through the "--hive-persisted-documents-token <token>" option or the config.'
|
1348
1013
|
);
|
1349
1014
|
process.exit(1);
|
1350
1015
|
}
|
@@ -1372,12 +1037,13 @@ async function runSupergraph({ log }, config) {
|
|
1372
1037
|
if (typeof config.supergraph === "string" && isValidPath(config.supergraph) && !isUrl(config.supergraph)) {
|
1373
1038
|
const supergraphPath = config.supergraph;
|
1374
1039
|
absSchemaPath = isAbsolute(supergraphPath) ? String(supergraphPath) : resolve(process.cwd(), supergraphPath);
|
1375
|
-
log.info(
|
1040
|
+
log.info("Reading supergraph from %s", absSchemaPath);
|
1376
1041
|
try {
|
1377
1042
|
await lstat(absSchemaPath);
|
1378
1043
|
} catch {
|
1379
1044
|
log.error(
|
1380
|
-
|
1045
|
+
"Could not read supergraph from %s. Make sure the file exists.",
|
1046
|
+
absSchemaPath
|
1381
1047
|
);
|
1382
1048
|
process.exit(1);
|
1383
1049
|
}
|
@@ -1385,10 +1051,10 @@ async function runSupergraph({ log }, config) {
|
|
1385
1051
|
if (absSchemaPath) {
|
1386
1052
|
delete config.pollingInterval;
|
1387
1053
|
if (cluster.isPrimary) {
|
1388
|
-
log.info(
|
1054
|
+
log.info("Watching %s for changes", absSchemaPath);
|
1389
1055
|
const ctrl = new AbortController();
|
1390
1056
|
registerTerminateHandler((signal) => {
|
1391
|
-
log.info(
|
1057
|
+
log.info("Closing watcher for %s on %s", absSchemaPath, signal);
|
1392
1058
|
return ctrl.abort(`Process terminated on ${signal}`);
|
1393
1059
|
});
|
1394
1060
|
(async function watcher() {
|
@@ -1398,7 +1064,7 @@ async function runSupergraph({ log }, config) {
|
|
1398
1064
|
if (f.eventType === "rename") {
|
1399
1065
|
throw new Error(`Supergraph file was renamed to "${f.filename}"`);
|
1400
1066
|
}
|
1401
|
-
log.info(
|
1067
|
+
log.info("%s changed. Invalidating supergraph...", absSchemaPath);
|
1402
1068
|
if (config.fork && config.fork > 1) {
|
1403
1069
|
for (const workerId in cluster.workers) {
|
1404
1070
|
cluster.workers[workerId].send("invalidateUnifiedGraph");
|
@@ -1409,9 +1075,9 @@ async function runSupergraph({ log }, config) {
|
|
1409
1075
|
}
|
1410
1076
|
})().catch((e) => {
|
1411
1077
|
if (e.name === "AbortError") return;
|
1412
|
-
log.error(
|
1078
|
+
log.error(e, "Watcher for %s closed with an error", absSchemaPath);
|
1413
1079
|
}).then(() => {
|
1414
|
-
log.info(
|
1080
|
+
log.info("Watcher for %s successfuly closed", absSchemaPath);
|
1415
1081
|
});
|
1416
1082
|
}
|
1417
1083
|
}
|
@@ -1441,12 +1107,13 @@ async function runSupergraph({ log }, config) {
|
|
1441
1107
|
}
|
1442
1108
|
const runtime = createGatewayRuntime(config);
|
1443
1109
|
if (absSchemaPath) {
|
1444
|
-
log.info(
|
1110
|
+
log.info("Serving local supergraph from %s", absSchemaPath);
|
1445
1111
|
} else if (isUrl(String(config.supergraph))) {
|
1446
|
-
log.info(
|
1112
|
+
log.info("Serving remote supergraph from %s", config.supergraph);
|
1447
1113
|
} else if (typeof config.supergraph === "object" && "type" in config.supergraph && config.supergraph.type === "hive") {
|
1448
1114
|
log.info(
|
1449
|
-
|
1115
|
+
"Serving supergraph from Hive CDN at %s",
|
1116
|
+
config.supergraph.endpoint
|
1450
1117
|
);
|
1451
1118
|
} else {
|
1452
1119
|
log.info("Serving supergraph from config");
|
@@ -1598,7 +1265,7 @@ let cli = new Command().configureHelp({
|
|
1598
1265
|
);
|
1599
1266
|
async function run(userCtx) {
|
1600
1267
|
const ctx = {
|
1601
|
-
log: userCtx.log ||
|
1268
|
+
log: userCtx.log || new Logger(),
|
1602
1269
|
productName: "Hive Gateway",
|
1603
1270
|
productDescription: "Federated GraphQL Gateway",
|
1604
1271
|
productPackageName: "@graphql-hive/gateway",
|
@@ -1634,4 +1301,4 @@ function enableModuleCachingIfPossible() {
|
|
1634
1301
|
}
|
1635
1302
|
}
|
1636
1303
|
|
1637
|
-
export { getBuiltinPluginsFromConfig as a, defaultOptions as b,
|
1304
|
+
export { getBuiltinPluginsFromConfig as a, defaultOptions as b, defineConfig as d, enableModuleCachingIfPossible as e, getCacheInstanceFromConfig as g, handleNodeWarnings as h, run as r };
|