@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
@@ -5,10 +5,10 @@ var module$1 = require('node:module');
|
|
5
5
|
var node_os = require('node:os');
|
6
6
|
var node_path = require('node:path');
|
7
7
|
var extraTypings = require('@commander-js/extra-typings');
|
8
|
-
var
|
9
|
-
var utils = require('@graphql-mesh/utils');
|
8
|
+
var logger = require('@graphql-hive/logger');
|
10
9
|
var gatewayRuntime = require('@graphql-hive/gateway-runtime');
|
11
10
|
var pubsub = require('@graphql-hive/pubsub');
|
11
|
+
var utils = require('@graphql-mesh/utils');
|
12
12
|
var promises = require('node:fs/promises');
|
13
13
|
var node_url = require('node:url');
|
14
14
|
var node_fs = require('node:fs');
|
@@ -78,266 +78,6 @@ function parse(str = '', format = 'ms') {
|
|
78
78
|
return result && ((result / (parse.unit[format] || 1)) * (str[0] === '-' ? -1 : 1))
|
79
79
|
}
|
80
80
|
|
81
|
-
// Taken from graphql-js
|
82
|
-
// https://github.com/graphql/graphql-js/blob/main/src/jsutils/inspect.ts
|
83
|
-
const MAX_RECURSIVE_DEPTH = 3;
|
84
|
-
/**
|
85
|
-
* Used to print values in error messages.
|
86
|
-
*/
|
87
|
-
function inspect(value) {
|
88
|
-
return formatValue(value, []);
|
89
|
-
}
|
90
|
-
function formatValue(value, seenValues) {
|
91
|
-
switch (typeof value) {
|
92
|
-
case 'string':
|
93
|
-
return JSON.stringify(value);
|
94
|
-
case 'function':
|
95
|
-
return value.name ? `[function ${value.name}]` : '[function]';
|
96
|
-
case 'object':
|
97
|
-
return formatObjectValue(value, seenValues);
|
98
|
-
default:
|
99
|
-
return String(value);
|
100
|
-
}
|
101
|
-
}
|
102
|
-
function formatError(value) {
|
103
|
-
// eslint-disable-next-line no-constant-condition
|
104
|
-
if ((value.name = 'GraphQLError')) {
|
105
|
-
return value.toString();
|
106
|
-
}
|
107
|
-
return `${value.name}: ${value.message};\n ${value.stack}`;
|
108
|
-
}
|
109
|
-
function formatObjectValue(value, previouslySeenValues) {
|
110
|
-
if (value === null) {
|
111
|
-
return 'null';
|
112
|
-
}
|
113
|
-
if (value instanceof Error) {
|
114
|
-
if (value.name === 'AggregateError') {
|
115
|
-
return (formatError(value) +
|
116
|
-
'\n' +
|
117
|
-
formatArray(value.errors, previouslySeenValues));
|
118
|
-
}
|
119
|
-
return formatError(value);
|
120
|
-
}
|
121
|
-
if (previouslySeenValues.includes(value)) {
|
122
|
-
return '[Circular]';
|
123
|
-
}
|
124
|
-
const seenValues = [...previouslySeenValues, value];
|
125
|
-
if (isJSONable(value)) {
|
126
|
-
const jsonValue = value.toJSON();
|
127
|
-
// check for infinite recursion
|
128
|
-
if (jsonValue !== value) {
|
129
|
-
return typeof jsonValue === 'string' ? jsonValue : formatValue(jsonValue, seenValues);
|
130
|
-
}
|
131
|
-
}
|
132
|
-
else if (Array.isArray(value)) {
|
133
|
-
return formatArray(value, seenValues);
|
134
|
-
}
|
135
|
-
return formatObject(value, seenValues);
|
136
|
-
}
|
137
|
-
function isJSONable(value) {
|
138
|
-
return typeof value.toJSON === 'function';
|
139
|
-
}
|
140
|
-
function formatObject(object, seenValues) {
|
141
|
-
const entries = Object.entries(object);
|
142
|
-
if (entries.length === 0) {
|
143
|
-
return '{}';
|
144
|
-
}
|
145
|
-
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
146
|
-
return '[' + getObjectTag(object) + ']';
|
147
|
-
}
|
148
|
-
const properties = entries.map(([key, value]) => key + ': ' + formatValue(value, seenValues));
|
149
|
-
return '{ ' + properties.join(', ') + ' }';
|
150
|
-
}
|
151
|
-
function formatArray(array, seenValues) {
|
152
|
-
if (array.length === 0) {
|
153
|
-
return '[]';
|
154
|
-
}
|
155
|
-
if (seenValues.length > MAX_RECURSIVE_DEPTH) {
|
156
|
-
return '[Array]';
|
157
|
-
}
|
158
|
-
const len = array.length;
|
159
|
-
const items = [];
|
160
|
-
for (let i = 0; i < len; ++i) {
|
161
|
-
items.push(formatValue(array[i], seenValues));
|
162
|
-
}
|
163
|
-
return '[' + items.join(', ') + ']';
|
164
|
-
}
|
165
|
-
function getObjectTag(object) {
|
166
|
-
const tag = Object.prototype.toString
|
167
|
-
.call(object)
|
168
|
-
.replace(/^\[object /, '')
|
169
|
-
.replace(/]$/, '');
|
170
|
-
if (tag === 'Object' && typeof object.constructor === 'function') {
|
171
|
-
const name = object.constructor.name;
|
172
|
-
if (typeof name === 'string' && name !== '') {
|
173
|
-
return name;
|
174
|
-
}
|
175
|
-
}
|
176
|
-
return tag;
|
177
|
-
}
|
178
|
-
|
179
|
-
function truthy(val) {
|
180
|
-
return val === true || val === 1 || ["1", "t", "true", "y", "yes"].includes(String(val));
|
181
|
-
}
|
182
|
-
class JSONLogger {
|
183
|
-
name;
|
184
|
-
meta;
|
185
|
-
logLevel;
|
186
|
-
console;
|
187
|
-
constructor(opts) {
|
188
|
-
this.name = opts?.name;
|
189
|
-
this.console = opts?.console || console;
|
190
|
-
this.meta = opts?.meta || {};
|
191
|
-
const debugStrs = [crossHelpers.process.env["DEBUG"], globalThis.DEBUG];
|
192
|
-
if (opts?.level != null) {
|
193
|
-
this.logLevel = opts.level;
|
194
|
-
} else {
|
195
|
-
this.logLevel = utils.LogLevel.info;
|
196
|
-
for (const debugStr of debugStrs) {
|
197
|
-
if (debugStr) {
|
198
|
-
if (truthy(debugStr)) {
|
199
|
-
this.logLevel = utils.LogLevel.debug;
|
200
|
-
break;
|
201
|
-
}
|
202
|
-
if (opts?.name) {
|
203
|
-
if (debugStr?.toString()?.includes(opts.name)) {
|
204
|
-
this.logLevel = utils.LogLevel.debug;
|
205
|
-
break;
|
206
|
-
}
|
207
|
-
}
|
208
|
-
}
|
209
|
-
}
|
210
|
-
}
|
211
|
-
}
|
212
|
-
log(...messageArgs) {
|
213
|
-
if (this.logLevel > utils.LogLevel.info) {
|
214
|
-
return;
|
215
|
-
}
|
216
|
-
const finalMessage = this.prepareFinalMessage("info", messageArgs);
|
217
|
-
this.console.log(finalMessage);
|
218
|
-
}
|
219
|
-
warn(...messageArgs) {
|
220
|
-
if (this.logLevel > utils.LogLevel.warn) {
|
221
|
-
return;
|
222
|
-
}
|
223
|
-
const finalMessage = this.prepareFinalMessage("warn", messageArgs);
|
224
|
-
this.console.warn(finalMessage);
|
225
|
-
}
|
226
|
-
info(...messageArgs) {
|
227
|
-
if (this.logLevel > utils.LogLevel.info) {
|
228
|
-
return;
|
229
|
-
}
|
230
|
-
const finalMessage = this.prepareFinalMessage("info", messageArgs);
|
231
|
-
this.console.info(finalMessage);
|
232
|
-
}
|
233
|
-
error(...messageArgs) {
|
234
|
-
if (this.logLevel > utils.LogLevel.error) {
|
235
|
-
return;
|
236
|
-
}
|
237
|
-
const finalMessage = this.prepareFinalMessage("error", messageArgs);
|
238
|
-
this.console.error(finalMessage);
|
239
|
-
}
|
240
|
-
debug(...messageArgs) {
|
241
|
-
if (this.logLevel > utils.LogLevel.debug) {
|
242
|
-
return;
|
243
|
-
}
|
244
|
-
const finalMessage = this.prepareFinalMessage("debug", messageArgs);
|
245
|
-
this.console.debug(finalMessage);
|
246
|
-
}
|
247
|
-
child(nameOrMeta) {
|
248
|
-
let newName;
|
249
|
-
let newMeta;
|
250
|
-
if (typeof nameOrMeta === "string") {
|
251
|
-
newName = this.name ? `${this.name}, ${nameOrMeta}` : nameOrMeta;
|
252
|
-
newMeta = this.meta;
|
253
|
-
} else if (typeof nameOrMeta === "object") {
|
254
|
-
newName = this.name;
|
255
|
-
newMeta = { ...this.meta, ...nameOrMeta };
|
256
|
-
} else {
|
257
|
-
throw new Error("Invalid argument type");
|
258
|
-
}
|
259
|
-
return new JSONLogger({
|
260
|
-
name: newName,
|
261
|
-
meta: newMeta,
|
262
|
-
level: this.logLevel,
|
263
|
-
console: this.console
|
264
|
-
});
|
265
|
-
}
|
266
|
-
addPrefix(prefix) {
|
267
|
-
if (typeof prefix === "string") {
|
268
|
-
this.name = this.name ? `${this.name}, ${prefix}` : prefix;
|
269
|
-
} else if (typeof prefix === "object") {
|
270
|
-
this.meta = { ...this.meta, ...prefix };
|
271
|
-
}
|
272
|
-
return this;
|
273
|
-
}
|
274
|
-
prepareFinalMessage(level, messageArgs) {
|
275
|
-
const flattenedMessageArgs = messageArgs.flat(Infinity).flatMap((messageArg) => {
|
276
|
-
if (typeof messageArg === "function") {
|
277
|
-
messageArg = messageArg();
|
278
|
-
}
|
279
|
-
if (messageArg?.toJSON) {
|
280
|
-
messageArg = messageArg.toJSON();
|
281
|
-
}
|
282
|
-
if (messageArg instanceof AggregateError) {
|
283
|
-
return messageArg.errors;
|
284
|
-
}
|
285
|
-
return messageArg;
|
286
|
-
});
|
287
|
-
const finalMessage = {
|
288
|
-
...this.meta,
|
289
|
-
level,
|
290
|
-
time: (/* @__PURE__ */ new Date()).toISOString()
|
291
|
-
};
|
292
|
-
if (this.name) {
|
293
|
-
finalMessage["name"] = this.name;
|
294
|
-
}
|
295
|
-
const extras = [];
|
296
|
-
for (let messageArg of flattenedMessageArgs) {
|
297
|
-
if (messageArg == null) {
|
298
|
-
continue;
|
299
|
-
}
|
300
|
-
const typeofMessageArg = typeof messageArg;
|
301
|
-
if (typeofMessageArg === "string" || typeofMessageArg === "number" || typeofMessageArg === "boolean") {
|
302
|
-
finalMessage["msg"] = finalMessage["msg"] ? finalMessage["msg"] + ", " + messageArg : messageArg;
|
303
|
-
} else if (typeofMessageArg === "object") {
|
304
|
-
if (messageArg instanceof Error) {
|
305
|
-
finalMessage["msg"] = finalMessage["msg"] ? finalMessage["msg"] + ", " + messageArg.message : messageArg.message;
|
306
|
-
finalMessage["stack"] = messageArg.stack;
|
307
|
-
} else if (Object.prototype.toString.call(messageArg).startsWith("[object")) {
|
308
|
-
Object.assign(finalMessage, messageArg);
|
309
|
-
} else {
|
310
|
-
extras.push(messageArg);
|
311
|
-
}
|
312
|
-
}
|
313
|
-
}
|
314
|
-
if (extras.length) {
|
315
|
-
if (extras.length === 1) {
|
316
|
-
finalMessage["extras"] = inspect(extras[0]);
|
317
|
-
} else {
|
318
|
-
finalMessage["extras"] = extras.map((extra) => inspect(extra));
|
319
|
-
}
|
320
|
-
}
|
321
|
-
return JSON.stringify(finalMessage);
|
322
|
-
}
|
323
|
-
}
|
324
|
-
|
325
|
-
function getDefaultLogger(opts) {
|
326
|
-
const logFormat = crossHelpers.process.env["LOG_FORMAT"] || globalThis.LOG_FORMAT;
|
327
|
-
if (logFormat) {
|
328
|
-
if (logFormat.toLowerCase() === "json") {
|
329
|
-
return new JSONLogger(opts);
|
330
|
-
} else if (logFormat.toLowerCase() === "pretty") {
|
331
|
-
return new utils.DefaultLogger(opts?.name, opts?.level);
|
332
|
-
}
|
333
|
-
}
|
334
|
-
const nodeEnv = crossHelpers.process.env["NODE_ENV"] || globalThis.NODE_ENV;
|
335
|
-
if (nodeEnv === "production") {
|
336
|
-
return new JSONLogger(opts);
|
337
|
-
}
|
338
|
-
return new utils.DefaultLogger(opts?.name, opts?.level);
|
339
|
-
}
|
340
|
-
|
341
81
|
const defaultConfigExtensions = [
|
342
82
|
".ts",
|
343
83
|
".mts",
|
@@ -411,12 +151,7 @@ async function getBuiltinPluginsFromConfig(config, ctx) {
|
|
411
151
|
}
|
412
152
|
if (config.openTelemetry) {
|
413
153
|
const { useOpenTelemetry } = await import('@graphql-mesh/plugin-opentelemetry');
|
414
|
-
plugins.push(
|
415
|
-
useOpenTelemetry({
|
416
|
-
logger: ctx.logger,
|
417
|
-
...config.openTelemetry
|
418
|
-
})
|
419
|
-
);
|
154
|
+
plugins.push(useOpenTelemetry({ ...config.openTelemetry, log: ctx.log }));
|
420
155
|
}
|
421
156
|
if (config.rateLimiting) {
|
422
157
|
const { default: useMeshRateLimit } = await import('@graphql-mesh/plugin-rate-limit');
|
@@ -475,7 +210,9 @@ async function getCacheInstanceFromConfig(config, ctx) {
|
|
475
210
|
const { default: RedisCache } = await import('@graphql-mesh/cache-redis');
|
476
211
|
return new RedisCache({
|
477
212
|
...ctx,
|
478
|
-
...config.cache
|
213
|
+
...config.cache,
|
214
|
+
// TODO: use new logger
|
215
|
+
logger: logger.LegacyLogger.from(ctx.log)
|
479
216
|
});
|
480
217
|
}
|
481
218
|
case "cfw-kv": {
|
@@ -494,7 +231,7 @@ async function getCacheInstanceFromConfig(config, ctx) {
|
|
494
231
|
}
|
495
232
|
}
|
496
233
|
if (config.cache.type !== "localforage") {
|
497
|
-
ctx.
|
234
|
+
ctx.log.warn(
|
498
235
|
"Unknown cache type, falling back to localforage",
|
499
236
|
config.cache
|
500
237
|
);
|
@@ -561,7 +298,7 @@ async function startBunServer(gwRuntime, opts) {
|
|
561
298
|
};
|
562
299
|
}
|
563
300
|
const server = Bun.serve(serverOptions);
|
564
|
-
opts.log.info(
|
301
|
+
opts.log.info("Listening on %s", server.url);
|
565
302
|
gwRuntime.disposableStack.use(server);
|
566
303
|
}
|
567
304
|
|
@@ -628,7 +365,7 @@ async function startNodeHttpServer(gwRuntime, opts) {
|
|
628
365
|
);
|
629
366
|
}
|
630
367
|
const url = `${protocol}://${host}:${port}`.replace("0.0.0.0", "localhost");
|
631
|
-
log.debug(
|
368
|
+
log.debug("Starting server on %s", url);
|
632
369
|
if (!disableWebsockets) {
|
633
370
|
log.debug("Setting up WebSocket server");
|
634
371
|
const { WebSocketServer } = await import('ws');
|
@@ -646,12 +383,12 @@ async function startNodeHttpServer(gwRuntime, opts) {
|
|
646
383
|
);
|
647
384
|
gwRuntime.disposableStack.defer(
|
648
385
|
() => new Promise((resolve, reject) => {
|
649
|
-
log.info(
|
386
|
+
log.info("Stopping the WebSocket server");
|
650
387
|
wsServer.close((err) => {
|
651
388
|
if (err) {
|
652
389
|
return reject(err);
|
653
390
|
}
|
654
|
-
log.info(
|
391
|
+
log.info("Stopped the WebSocket server successfully");
|
655
392
|
return resolve();
|
656
393
|
});
|
657
394
|
})
|
@@ -660,14 +397,14 @@ async function startNodeHttpServer(gwRuntime, opts) {
|
|
660
397
|
return new Promise((resolve, reject) => {
|
661
398
|
server.once("error", reject);
|
662
399
|
server.listen(port, host, () => {
|
663
|
-
log.info(
|
400
|
+
log.info("Listening on %s", url);
|
664
401
|
gwRuntime.disposableStack.defer(
|
665
402
|
() => new Promise((resolve2) => {
|
666
403
|
process.stderr.write("\n");
|
667
|
-
log.info(
|
404
|
+
log.info("Stopping the server");
|
668
405
|
server.closeAllConnections();
|
669
406
|
server.close(() => {
|
670
|
-
log.info(
|
407
|
+
log.info("Stopped the server successfully");
|
671
408
|
return resolve2();
|
672
409
|
});
|
673
410
|
})
|
@@ -677,68 +414,7 @@ async function startNodeHttpServer(gwRuntime, opts) {
|
|
677
414
|
});
|
678
415
|
}
|
679
416
|
|
680
|
-
function
|
681
|
-
return async function startUwsServer(gwRuntime, opts) {
|
682
|
-
const {
|
683
|
-
log,
|
684
|
-
host = defaultOptions.host,
|
685
|
-
port = defaultOptions.port,
|
686
|
-
sslCredentials,
|
687
|
-
maxHeaderSize,
|
688
|
-
disableWebsockets
|
689
|
-
} = opts;
|
690
|
-
if (maxHeaderSize) {
|
691
|
-
process.env["UWS_HTTP_MAX_HEADER_SIZE"] = maxHeaderSize.toString();
|
692
|
-
}
|
693
|
-
let app;
|
694
|
-
let protocol;
|
695
|
-
if (sslCredentials) {
|
696
|
-
protocol = "https";
|
697
|
-
app = uws.SSLApp({
|
698
|
-
key_file_name: sslCredentials.key_file_name,
|
699
|
-
cert_file_name: sslCredentials.cert_file_name,
|
700
|
-
ca_file_name: sslCredentials.ca_file_name,
|
701
|
-
passphrase: sslCredentials.passphrase,
|
702
|
-
dh_params_file_name: sslCredentials.dh_params_file_name,
|
703
|
-
ssl_ciphers: sslCredentials.ssl_ciphers,
|
704
|
-
ssl_prefer_low_memory_usage: sslCredentials.ssl_prefer_low_memory_usage
|
705
|
-
});
|
706
|
-
} else {
|
707
|
-
protocol = "http";
|
708
|
-
app = uws.App();
|
709
|
-
}
|
710
|
-
const url = `${protocol}://${host}:${port}`.replace("0.0.0.0", "localhost");
|
711
|
-
log.debug(`Starting server on ${url}`);
|
712
|
-
if (!disableWebsockets) {
|
713
|
-
log.debug("Setting up WebSocket server");
|
714
|
-
const { makeBehavior } = await import('graphql-ws/use/uWebSockets');
|
715
|
-
const wsBehavior = makeBehavior(
|
716
|
-
gatewayRuntime.getGraphQLWSOptions(gwRuntime, (ctx) => ({
|
717
|
-
req: ctx.extra?.persistedRequest,
|
718
|
-
socket: ctx.extra?.socket
|
719
|
-
}))
|
720
|
-
);
|
721
|
-
app.ws(gwRuntime.graphqlEndpoint, wsBehavior);
|
722
|
-
}
|
723
|
-
app.any("/*", gwRuntime);
|
724
|
-
return new Promise((resolve, reject) => {
|
725
|
-
app.listen(host, port, (listenSocket) => {
|
726
|
-
if (listenSocket) {
|
727
|
-
log.info(`Listening on ${url}`);
|
728
|
-
} else {
|
729
|
-
reject(new Error(`Failed to start server on ${url}`));
|
730
|
-
}
|
731
|
-
});
|
732
|
-
gwRuntime.disposableStack.defer(() => {
|
733
|
-
log.info(`Stopping the server`);
|
734
|
-
app.close();
|
735
|
-
resolve();
|
736
|
-
});
|
737
|
-
});
|
738
|
-
};
|
739
|
-
}
|
740
|
-
|
741
|
-
async function startServerForRuntime(runtime, {
|
417
|
+
function startServerForRuntime(runtime, {
|
742
418
|
log,
|
743
419
|
host = defaultOptions.host,
|
744
420
|
port = defaultOptions.port,
|
@@ -748,7 +424,7 @@ async function startServerForRuntime(runtime, {
|
|
748
424
|
}) {
|
749
425
|
process.on("message", (message) => {
|
750
426
|
if (message === "invalidateUnifiedGraph") {
|
751
|
-
log.info(
|
427
|
+
log.info("Invalidating Supergraph");
|
752
428
|
runtime.invalidateUnifiedGraph();
|
753
429
|
}
|
754
430
|
});
|
@@ -760,18 +436,7 @@ async function startServerForRuntime(runtime, {
|
|
760
436
|
disableWebsockets,
|
761
437
|
...sslCredentials ? { sslCredentials } : {}
|
762
438
|
};
|
763
|
-
|
764
|
-
if (globalThis.Bun) {
|
765
|
-
startServer = startBunServer;
|
766
|
-
} else {
|
767
|
-
try {
|
768
|
-
const uws = await Promise.resolve().then(function () { return require('./ESM_wrapper-D0jQu0hQ.cjs'); });
|
769
|
-
log.info("uWebSockets.js is available, using it for the server");
|
770
|
-
startServer = createUWSStartFn(uws);
|
771
|
-
} catch {
|
772
|
-
startServer = startNodeHttpServer;
|
773
|
-
}
|
774
|
-
}
|
439
|
+
const startServer = globalThis.Bun ? startBunServer : startNodeHttpServer;
|
775
440
|
return startServer(runtime, serverOpts);
|
776
441
|
}
|
777
442
|
|
@@ -780,7 +445,7 @@ function handleFork(log, config) {
|
|
780
445
|
if (cluster__default.default.isPrimary && config.fork && config.fork > 1) {
|
781
446
|
const workers = /* @__PURE__ */ new Set();
|
782
447
|
let expectedToExit = false;
|
783
|
-
log.debug(
|
448
|
+
log.debug("Forking %d workers", config.fork);
|
784
449
|
for (let i = 0; i < config.fork; i++) {
|
785
450
|
const worker = cluster__default.default.fork();
|
786
451
|
const workerLogger = log.child({ worker: worker.id });
|
@@ -792,25 +457,23 @@ function handleFork(log, config) {
|
|
792
457
|
logData["code"] = code;
|
793
458
|
}
|
794
459
|
if (expectedToExit) {
|
795
|
-
workerLogger.debug("exited"
|
460
|
+
workerLogger.debug(logData, "exited");
|
796
461
|
} else {
|
797
462
|
workerLogger.error(
|
798
|
-
|
799
|
-
|
463
|
+
logData,
|
464
|
+
"Exited unexpectedly. A restart is recommended to ensure the stability of the service"
|
800
465
|
);
|
801
466
|
}
|
802
467
|
workers.delete(worker);
|
803
468
|
if (!expectedToExit && workers.size === 0) {
|
804
|
-
log.error(
|
469
|
+
log.error(logData, "All workers exited unexpectedly. Exiting...");
|
805
470
|
process.exit(1);
|
806
471
|
}
|
807
472
|
});
|
808
473
|
workers.add(worker);
|
809
474
|
}
|
810
475
|
utils.registerTerminateHandler((signal) => {
|
811
|
-
log.info("Killing workers",
|
812
|
-
signal
|
813
|
-
});
|
476
|
+
log.info("Killing workers on %s", signal);
|
814
477
|
expectedToExit = true;
|
815
478
|
workers.forEach((w) => {
|
816
479
|
w.kill(signal);
|
@@ -819,15 +482,15 @@ function handleFork(log, config) {
|
|
819
482
|
return true;
|
820
483
|
}
|
821
484
|
} catch (e) {
|
822
|
-
log.error(
|
485
|
+
log.error(
|
486
|
+
// @ts-expect-error very likely an instanceof error
|
487
|
+
e,
|
488
|
+
"Error while forking workers"
|
489
|
+
);
|
823
490
|
}
|
824
491
|
return false;
|
825
492
|
}
|
826
493
|
|
827
|
-
function handleLoggingConfig(loggingConfig, ctx) {
|
828
|
-
ctx.log = gatewayRuntime.handleLoggingConfig(loggingConfig, ctx.log);
|
829
|
-
}
|
830
|
-
|
831
494
|
function handleReportingConfig(ctx, loadedConfig, cliOpts) {
|
832
495
|
const confOpts = {
|
833
496
|
...loadedConfig.reporting?.type === "hive" ? {
|
@@ -843,34 +506,34 @@ function handleReportingConfig(ctx, loadedConfig, cliOpts) {
|
|
843
506
|
const opts = { ...confOpts, ...cliOpts };
|
844
507
|
if (cliOpts.hiveRegistryToken && cliOpts.hiveUsageAccessToken) {
|
845
508
|
ctx.log.error(
|
846
|
-
|
509
|
+
'Cannot use "--hive-registry-token" with "--hive-usage-access-token". Please use "--hive-usage-target" and "--hive-usage-access-token" or the config instead.'
|
847
510
|
);
|
848
511
|
process.exit(1);
|
849
512
|
}
|
850
513
|
if (cliOpts.hiveRegistryToken && opts.hiveUsageTarget) {
|
851
514
|
ctx.log.error(
|
852
|
-
|
515
|
+
'Cannot use "--hive-registry-token" with a target. Please use "--hive-usage-target" and "--hive-usage-access-token" or the config instead.'
|
853
516
|
);
|
854
517
|
process.exit(1);
|
855
518
|
}
|
856
519
|
if (opts.hiveUsageTarget && !opts.hiveUsageAccessToken) {
|
857
520
|
ctx.log.error(
|
858
|
-
|
521
|
+
'Hive usage target needs an access token. Please provide it through the "--hive-usage-access-token <token>" option or the config.'
|
859
522
|
);
|
860
523
|
process.exit(1);
|
861
524
|
}
|
862
525
|
if (opts.hiveUsageAccessToken && !opts.hiveUsageTarget) {
|
863
526
|
ctx.log.error(
|
864
|
-
|
527
|
+
'Hive usage access token needs a target. Please provide it through the "--hive-usage-target <target>" option or the config.'
|
865
528
|
);
|
866
529
|
process.exit(1);
|
867
530
|
}
|
868
531
|
const hiveUsageAccessToken = opts.hiveUsageAccessToken || opts.hiveRegistryToken;
|
869
532
|
if (hiveUsageAccessToken) {
|
870
533
|
if (opts.hiveUsageTarget) {
|
871
|
-
ctx.log.info(
|
534
|
+
ctx.log.info("Configuring Hive usage reporting");
|
872
535
|
} else {
|
873
|
-
ctx.log.info(
|
536
|
+
ctx.log.info("Configuring Hive registry reporting");
|
874
537
|
}
|
875
538
|
return {
|
876
539
|
...loadedConfig.reporting,
|
@@ -880,7 +543,7 @@ function handleReportingConfig(ctx, loadedConfig, cliOpts) {
|
|
880
543
|
};
|
881
544
|
}
|
882
545
|
if (opts.apolloKey) {
|
883
|
-
ctx.log.info(
|
546
|
+
ctx.log.info("Configuring Apollo GraphOS registry reporting");
|
884
547
|
if (!opts.apolloGraphRef?.includes("@")) {
|
885
548
|
ctx.log.error(
|
886
549
|
`Apollo GraphOS requires a graph ref in the format <graph-id>@<graph-variant>. Please provide a valid graph ref ${opts.apolloGraphRef ? `not ${opts.apolloGraphRef}` : ""}.`
|
@@ -937,11 +600,10 @@ const addCommand$2 = (ctx, cli) => cli.command("proxy").description(
|
|
937
600
|
// TODO: take schema from optsWithGlobals once https://github.com/commander-js/extra-typings/pull/76 is merged
|
938
601
|
this.opts().schema || hiveCdnEndpoint
|
939
602
|
);
|
940
|
-
const hiveCdnLogger = ctx.log.child({ source: "Hive CDN" });
|
941
603
|
if (hiveCdnEndpointOpt) {
|
942
604
|
if (hiveCdnKey) {
|
943
605
|
if (!utils.isUrl(hiveCdnEndpointOpt)) {
|
944
|
-
|
606
|
+
ctx.log.error(
|
945
607
|
"Endpoint must be a URL when providing --hive-cdn-key but got " + hiveCdnEndpointOpt
|
946
608
|
);
|
947
609
|
process.exit(1);
|
@@ -980,11 +642,11 @@ const addCommand$2 = (ctx, cli) => cli.command("proxy").description(
|
|
980
642
|
const pubsub$1 = loadedConfig.pubsub || new pubsub.PubSub();
|
981
643
|
const cwd = loadedConfig.cwd || process.cwd();
|
982
644
|
if (loadedConfig.logging != null) {
|
983
|
-
|
645
|
+
ctx.log = gatewayRuntime.createLoggerFromLogging(loadedConfig.logging);
|
984
646
|
}
|
985
647
|
const cache = await getCacheInstanceFromConfig(loadedConfig, {
|
986
648
|
pubsub: pubsub$1,
|
987
|
-
|
649
|
+
log: ctx.log,
|
988
650
|
cwd
|
989
651
|
});
|
990
652
|
const builtinPlugins = await getBuiltinPluginsFromConfig(
|
@@ -993,7 +655,7 @@ const addCommand$2 = (ctx, cli) => cli.command("proxy").description(
|
|
993
655
|
...opts
|
994
656
|
},
|
995
657
|
{
|
996
|
-
|
658
|
+
log: ctx.log,
|
997
659
|
cache}
|
998
660
|
);
|
999
661
|
const config = {
|
@@ -1098,11 +760,11 @@ const addCommand$1 = (ctx, cli) => cli.command("subgraph").description(
|
|
1098
760
|
const pubsub$1 = loadedConfig.pubsub || new pubsub.PubSub();
|
1099
761
|
const cwd = loadedConfig.cwd || process.cwd();
|
1100
762
|
if (loadedConfig.logging != null) {
|
1101
|
-
|
763
|
+
ctx.log = gatewayRuntime.createLoggerFromLogging(loadedConfig.logging);
|
1102
764
|
}
|
1103
765
|
const cache = await getCacheInstanceFromConfig(loadedConfig, {
|
1104
766
|
pubsub: pubsub$1,
|
1105
|
-
|
767
|
+
log: ctx.log,
|
1106
768
|
cwd
|
1107
769
|
});
|
1108
770
|
const builtinPlugins = await getBuiltinPluginsFromConfig(
|
@@ -1111,7 +773,7 @@ const addCommand$1 = (ctx, cli) => cli.command("subgraph").description(
|
|
1111
773
|
...opts
|
1112
774
|
},
|
1113
775
|
{
|
1114
|
-
|
776
|
+
log: ctx.log,
|
1115
777
|
cache}
|
1116
778
|
);
|
1117
779
|
const config = {
|
@@ -1222,12 +884,13 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1222
884
|
});
|
1223
885
|
let supergraph2 = "supergraph.graphql";
|
1224
886
|
if (schemaPathOrUrl) {
|
1225
|
-
ctx.log.info(
|
887
|
+
ctx.log.info("Supergraph will be loaded from %s", schemaPathOrUrl);
|
1226
888
|
if (hiveCdnKey) {
|
1227
|
-
ctx.log.info(
|
889
|
+
ctx.log.info("Using Hive CDN key");
|
1228
890
|
if (!utils.isUrl(schemaPathOrUrl)) {
|
1229
891
|
ctx.log.error(
|
1230
|
-
"Hive CDN endpoint must be a URL when providing --hive-cdn-key but got "
|
892
|
+
"Hive CDN endpoint must be a URL when providing --hive-cdn-key but got %s",
|
893
|
+
schemaPathOrUrl
|
1231
894
|
);
|
1232
895
|
process.exit(1);
|
1233
896
|
}
|
@@ -1237,10 +900,11 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1237
900
|
key: hiveCdnKey
|
1238
901
|
};
|
1239
902
|
} else if (apolloKey) {
|
1240
|
-
ctx.log.info(
|
903
|
+
ctx.log.info("Using GraphOS API key");
|
1241
904
|
if (!schemaPathOrUrl.includes("@")) {
|
1242
905
|
ctx.log.error(
|
1243
|
-
`Apollo GraphOS requires a graph ref in the format <graph-id>@<graph-variant> when providing --apollo-key. Please provide a valid graph ref not
|
906
|
+
`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.`,
|
907
|
+
schemaPathOrUrl
|
1244
908
|
);
|
1245
909
|
process.exit(1);
|
1246
910
|
}
|
@@ -1266,7 +930,7 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1266
930
|
);
|
1267
931
|
process.exit(1);
|
1268
932
|
}
|
1269
|
-
ctx.log.info(
|
933
|
+
ctx.log.info("Using Hive CDN endpoint %s", hiveCdnEndpoint);
|
1270
934
|
supergraph2 = {
|
1271
935
|
type: "hive",
|
1272
936
|
endpoint: hiveCdnEndpoint,
|
@@ -1275,17 +939,18 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1275
939
|
} else if (apolloGraphRef) {
|
1276
940
|
if (!apolloGraphRef.includes("@")) {
|
1277
941
|
ctx.log.error(
|
1278
|
-
|
942
|
+
"Apollo GraphOS requires a graph ref in the format <graph-id>@<graph-variant>. Please provide a valid graph ref not %s.",
|
943
|
+
apolloGraphRef
|
1279
944
|
);
|
1280
945
|
process.exit(1);
|
1281
946
|
}
|
1282
947
|
if (!apolloKey) {
|
1283
948
|
ctx.log.error(
|
1284
|
-
|
949
|
+
"Apollo GraphOS requires an API key. Please provide an API key using the --apollo-key option."
|
1285
950
|
);
|
1286
951
|
process.exit(1);
|
1287
952
|
}
|
1288
|
-
ctx.log.info(
|
953
|
+
ctx.log.info("Using Apollo Graph Ref %s", apolloGraphRef);
|
1289
954
|
supergraph2 = {
|
1290
955
|
type: "graphos",
|
1291
956
|
apiKey: apolloKey,
|
@@ -1295,7 +960,7 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1295
960
|
} else if ("supergraph" in loadedConfig) {
|
1296
961
|
supergraph2 = loadedConfig.supergraph;
|
1297
962
|
} else {
|
1298
|
-
ctx.log.info(
|
963
|
+
ctx.log.info("Using default supergraph location %s", supergraph2);
|
1299
964
|
}
|
1300
965
|
const registryConfig = {};
|
1301
966
|
const reporting = handleReportingConfig(ctx, loadedConfig, {
|
@@ -1311,11 +976,11 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1311
976
|
const pubsub$1 = loadedConfig.pubsub || new pubsub.PubSub();
|
1312
977
|
const cwd = loadedConfig.cwd || process.cwd();
|
1313
978
|
if (loadedConfig.logging != null) {
|
1314
|
-
|
979
|
+
ctx.log = gatewayRuntime.createLoggerFromLogging(loadedConfig.logging);
|
1315
980
|
}
|
1316
981
|
const cache = await getCacheInstanceFromConfig(loadedConfig, {
|
1317
982
|
pubsub: pubsub$1,
|
1318
|
-
|
983
|
+
log: ctx.log,
|
1319
984
|
cwd
|
1320
985
|
});
|
1321
986
|
const builtinPlugins = await getBuiltinPluginsFromConfig(
|
@@ -1324,7 +989,7 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1324
989
|
...opts
|
1325
990
|
},
|
1326
991
|
{
|
1327
|
-
|
992
|
+
log: ctx.log,
|
1328
993
|
cache}
|
1329
994
|
);
|
1330
995
|
const config = {
|
@@ -1351,7 +1016,7 @@ const addCommand = (ctx, cli) => cli.command("supergraph").description(
|
|
1351
1016
|
const token = hivePersistedDocumentsToken || loadedConfig.persistedDocuments && "token" in loadedConfig.persistedDocuments && loadedConfig.persistedDocuments.token;
|
1352
1017
|
if (!token) {
|
1353
1018
|
ctx.log.error(
|
1354
|
-
|
1019
|
+
'Hive persisted documents needs a CDN token. Please provide it through the "--hive-persisted-documents-token <token>" option or the config.'
|
1355
1020
|
);
|
1356
1021
|
process.exit(1);
|
1357
1022
|
}
|
@@ -1379,12 +1044,13 @@ async function runSupergraph({ log }, config) {
|
|
1379
1044
|
if (typeof config.supergraph === "string" && utils$1.isValidPath(config.supergraph) && !utils.isUrl(config.supergraph)) {
|
1380
1045
|
const supergraphPath = config.supergraph;
|
1381
1046
|
absSchemaPath = node_path.isAbsolute(supergraphPath) ? String(supergraphPath) : node_path.resolve(process.cwd(), supergraphPath);
|
1382
|
-
log.info(
|
1047
|
+
log.info("Reading supergraph from %s", absSchemaPath);
|
1383
1048
|
try {
|
1384
1049
|
await promises.lstat(absSchemaPath);
|
1385
1050
|
} catch {
|
1386
1051
|
log.error(
|
1387
|
-
|
1052
|
+
"Could not read supergraph from %s. Make sure the file exists.",
|
1053
|
+
absSchemaPath
|
1388
1054
|
);
|
1389
1055
|
process.exit(1);
|
1390
1056
|
}
|
@@ -1392,10 +1058,10 @@ async function runSupergraph({ log }, config) {
|
|
1392
1058
|
if (absSchemaPath) {
|
1393
1059
|
delete config.pollingInterval;
|
1394
1060
|
if (cluster__default.default.isPrimary) {
|
1395
|
-
log.info(
|
1061
|
+
log.info("Watching %s for changes", absSchemaPath);
|
1396
1062
|
const ctrl = new AbortController();
|
1397
1063
|
utils.registerTerminateHandler((signal) => {
|
1398
|
-
log.info(
|
1064
|
+
log.info("Closing watcher for %s on %s", absSchemaPath, signal);
|
1399
1065
|
return ctrl.abort(`Process terminated on ${signal}`);
|
1400
1066
|
});
|
1401
1067
|
(async function watcher() {
|
@@ -1405,7 +1071,7 @@ async function runSupergraph({ log }, config) {
|
|
1405
1071
|
if (f.eventType === "rename") {
|
1406
1072
|
throw new Error(`Supergraph file was renamed to "${f.filename}"`);
|
1407
1073
|
}
|
1408
|
-
log.info(
|
1074
|
+
log.info("%s changed. Invalidating supergraph...", absSchemaPath);
|
1409
1075
|
if (config.fork && config.fork > 1) {
|
1410
1076
|
for (const workerId in cluster__default.default.workers) {
|
1411
1077
|
cluster__default.default.workers[workerId].send("invalidateUnifiedGraph");
|
@@ -1416,9 +1082,9 @@ async function runSupergraph({ log }, config) {
|
|
1416
1082
|
}
|
1417
1083
|
})().catch((e) => {
|
1418
1084
|
if (e.name === "AbortError") return;
|
1419
|
-
log.error(
|
1085
|
+
log.error(e, "Watcher for %s closed with an error", absSchemaPath);
|
1420
1086
|
}).then(() => {
|
1421
|
-
log.info(
|
1087
|
+
log.info("Watcher for %s successfuly closed", absSchemaPath);
|
1422
1088
|
});
|
1423
1089
|
}
|
1424
1090
|
}
|
@@ -1448,12 +1114,13 @@ async function runSupergraph({ log }, config) {
|
|
1448
1114
|
}
|
1449
1115
|
const runtime = gatewayRuntime.createGatewayRuntime(config);
|
1450
1116
|
if (absSchemaPath) {
|
1451
|
-
log.info(
|
1117
|
+
log.info("Serving local supergraph from %s", absSchemaPath);
|
1452
1118
|
} else if (utils.isUrl(String(config.supergraph))) {
|
1453
|
-
log.info(
|
1119
|
+
log.info("Serving remote supergraph from %s", config.supergraph);
|
1454
1120
|
} else if (typeof config.supergraph === "object" && "type" in config.supergraph && config.supergraph.type === "hive") {
|
1455
1121
|
log.info(
|
1456
|
-
|
1122
|
+
"Serving supergraph from Hive CDN at %s",
|
1123
|
+
config.supergraph.endpoint
|
1457
1124
|
);
|
1458
1125
|
} else {
|
1459
1126
|
log.info("Serving supergraph from config");
|
@@ -1605,7 +1272,7 @@ let cli = new extraTypings.Command().configureHelp({
|
|
1605
1272
|
);
|
1606
1273
|
async function run(userCtx) {
|
1607
1274
|
const ctx = {
|
1608
|
-
log: userCtx.log ||
|
1275
|
+
log: userCtx.log || new logger.Logger(),
|
1609
1276
|
productName: "Hive Gateway",
|
1610
1277
|
productDescription: "Federated GraphQL Gateway",
|
1611
1278
|
productPackageName: "@graphql-hive/gateway",
|
@@ -1646,6 +1313,5 @@ exports.defineConfig = defineConfig;
|
|
1646
1313
|
exports.enableModuleCachingIfPossible = enableModuleCachingIfPossible;
|
1647
1314
|
exports.getBuiltinPluginsFromConfig = getBuiltinPluginsFromConfig;
|
1648
1315
|
exports.getCacheInstanceFromConfig = getCacheInstanceFromConfig;
|
1649
|
-
exports.getDefaultLogger = getDefaultLogger;
|
1650
1316
|
exports.handleNodeWarnings = handleNodeWarnings;
|
1651
1317
|
exports.run = run;
|