@graphql-mesh/fusion-runtime 0.11.12 → 0.11.13-alpha-cd2e85546d0c2bef716fc44935bc37a496a3ba57
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 +12 -0
- package/dist/index.cjs +75 -114
- package/dist/index.d.cts +13 -13
- package/dist/index.d.ts +13 -13
- package/dist/index.js +76 -115
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @graphql-mesh/fusion-runtime
|
|
2
2
|
|
|
3
|
+
## 0.11.13-alpha-cd2e85546d0c2bef716fc44935bc37a496a3ba57
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1030](https://github.com/graphql-hive/gateway/pull/1030) [`42269ef`](https://github.com/graphql-hive/gateway/commit/42269ef0b3b958d60960ace64487745c2ac97942) Thanks [@enisdenjo](https://github.com/enisdenjo)! - dependencies updates:
|
|
8
|
+
|
|
9
|
+
- Added dependency [`@graphql-hive/logger@workspace:^` ↗︎](https://www.npmjs.com/package/@graphql-hive/logger/v/workspace:^) (to `dependencies`)
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`42269ef`](https://github.com/graphql-hive/gateway/commit/42269ef0b3b958d60960ace64487745c2ac97942), [`744b4b9`](https://github.com/graphql-hive/gateway/commit/744b4b9af1ae277092c928fe83e5c1382b95cf09)]:
|
|
12
|
+
- @graphql-mesh/transport-common@0.7.35-alpha-cd2e85546d0c2bef716fc44935bc37a496a3ba57
|
|
13
|
+
- @graphql-hive/logger@1.0.0-alpha-cd2e85546d0c2bef716fc44935bc37a496a3ba57
|
|
14
|
+
|
|
3
15
|
## 0.11.12
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var instrumentation = require('@envelop/instrumentation');
|
|
4
|
+
var request = require('@graphql-hive/logger/request');
|
|
4
5
|
var transportCommon = require('@graphql-mesh/transport-common');
|
|
5
6
|
var utils$1 = require('@graphql-mesh/utils');
|
|
6
7
|
var batchExecute = require('@graphql-tools/batch-execute');
|
|
7
8
|
var utils = require('@graphql-tools/utils');
|
|
8
9
|
var promiseHelpers = require('@whatwg-node/promise-helpers');
|
|
9
10
|
var graphql = require('graphql');
|
|
11
|
+
var logger = require('@graphql-hive/logger');
|
|
10
12
|
var federation = require('@graphql-tools/federation');
|
|
11
13
|
var merge = require('@graphql-tools/merge');
|
|
12
14
|
var stitch = require('@graphql-tools/stitch');
|
|
@@ -597,7 +599,7 @@ const handleFederationSupergraph = function({
|
|
|
597
599
|
onDelegateHooks,
|
|
598
600
|
additionalTypeDefs: additionalTypeDefsFromConfig = [],
|
|
599
601
|
additionalResolvers: additionalResolversFromConfig = [],
|
|
600
|
-
|
|
602
|
+
log: rootLog
|
|
601
603
|
}) {
|
|
602
604
|
const additionalTypeDefs = [...utils.asArray(additionalTypeDefsFromConfig)];
|
|
603
605
|
const additionalResolvers = [...utils.asArray(additionalResolversFromConfig)];
|
|
@@ -660,7 +662,7 @@ const handleFederationSupergraph = function({
|
|
|
660
662
|
originalResolver,
|
|
661
663
|
typeName,
|
|
662
664
|
onDelegationStageExecuteHooks,
|
|
663
|
-
|
|
665
|
+
rootLog
|
|
664
666
|
);
|
|
665
667
|
}
|
|
666
668
|
}
|
|
@@ -705,7 +707,7 @@ const handleFederationSupergraph = function({
|
|
|
705
707
|
executableUnifiedGraph,
|
|
706
708
|
// @ts-expect-error Legacy Mesh RawSource is not compatible with new Mesh
|
|
707
709
|
subschemas,
|
|
708
|
-
logger,
|
|
710
|
+
logger.LegacyLogger.from(rootLog),
|
|
709
711
|
onDelegateHooks || []
|
|
710
712
|
);
|
|
711
713
|
const stitchingInfo = executableUnifiedGraph.extensions?.["stitchingInfo"];
|
|
@@ -720,16 +722,9 @@ const handleFederationSupergraph = function({
|
|
|
720
722
|
delegationPlanBuilder = newDelegationPlanBuilder;
|
|
721
723
|
}
|
|
722
724
|
const onDelegationPlanDoneHooks = [];
|
|
723
|
-
let
|
|
724
|
-
let requestId;
|
|
725
|
-
if (context?.request) {
|
|
726
|
-
requestId = utils$1.requestIdByRequest.get(context.request);
|
|
727
|
-
if (requestId) {
|
|
728
|
-
currentLogger = currentLogger?.child({ requestId });
|
|
729
|
-
}
|
|
730
|
-
}
|
|
725
|
+
let log = context.log;
|
|
731
726
|
if (sourceSubschema.name) {
|
|
732
|
-
|
|
727
|
+
log = log.child({
|
|
733
728
|
subgraph: sourceSubschema.name
|
|
734
729
|
});
|
|
735
730
|
}
|
|
@@ -742,7 +737,7 @@ const handleFederationSupergraph = function({
|
|
|
742
737
|
variables,
|
|
743
738
|
fragments,
|
|
744
739
|
fieldNodes,
|
|
745
|
-
|
|
740
|
+
log,
|
|
746
741
|
context,
|
|
747
742
|
info,
|
|
748
743
|
delegationPlanBuilder,
|
|
@@ -835,13 +830,7 @@ function getTransportExecutor({
|
|
|
835
830
|
getDisposeReason
|
|
836
831
|
}) {
|
|
837
832
|
const kind = transportEntry?.kind || "";
|
|
838
|
-
|
|
839
|
-
if (logger) {
|
|
840
|
-
if (subgraphName) {
|
|
841
|
-
logger = logger.child({ subgraph: subgraphName });
|
|
842
|
-
}
|
|
843
|
-
logger?.debug(`Loading transport "${kind}"`);
|
|
844
|
-
}
|
|
833
|
+
transportContext.log.debug(`Loading transport "${kind}"`);
|
|
845
834
|
return promiseHelpers.handleMaybePromise(
|
|
846
835
|
() => typeof transports === "function" ? transports(kind) : transports[kind],
|
|
847
836
|
(transport) => {
|
|
@@ -890,33 +879,29 @@ function getTransportExecutor({
|
|
|
890
879
|
const subgraphNameByExecutionRequest = /* @__PURE__ */ new WeakMap();
|
|
891
880
|
function getOnSubgraphExecute({
|
|
892
881
|
onSubgraphExecuteHooks,
|
|
893
|
-
transportContext
|
|
882
|
+
transportContext,
|
|
894
883
|
transportEntryMap,
|
|
895
884
|
getSubgraphSchema,
|
|
896
885
|
transportExecutorStack,
|
|
897
886
|
transports,
|
|
898
887
|
getDisposeReason,
|
|
899
888
|
batch = true,
|
|
900
|
-
instrumentation
|
|
889
|
+
instrumentation
|
|
901
890
|
}) {
|
|
902
891
|
const subgraphExecutorMap = /* @__PURE__ */ new Map();
|
|
903
892
|
return function onSubgraphExecute(subgraphName, executionRequest) {
|
|
904
893
|
subgraphNameByExecutionRequest.set(executionRequest, subgraphName);
|
|
905
894
|
let executor = subgraphExecutorMap.get(subgraphName);
|
|
906
895
|
if (executor == null) {
|
|
907
|
-
let
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
logger = logger.child({ requestId });
|
|
914
|
-
}
|
|
915
|
-
if (subgraphName) {
|
|
916
|
-
logger = logger.child({ subgraph: subgraphName });
|
|
917
|
-
}
|
|
918
|
-
logger.debug(`Initializing executor`);
|
|
896
|
+
let log = executionRequest.context?.request ? request.loggerForRequest(
|
|
897
|
+
transportContext.log,
|
|
898
|
+
executionRequest.context.request
|
|
899
|
+
) : transportContext.log;
|
|
900
|
+
if (subgraphName) {
|
|
901
|
+
log = log.child({ subgraph: subgraphName });
|
|
919
902
|
}
|
|
903
|
+
transportContext.log = log;
|
|
904
|
+
log.debug("Initializing executor");
|
|
920
905
|
executor = function lazyExecutor(subgraphExecReq) {
|
|
921
906
|
return promiseHelpers.handleMaybePromise(
|
|
922
907
|
() => (
|
|
@@ -944,7 +929,8 @@ function getOnSubgraphExecute({
|
|
|
944
929
|
subgraphName,
|
|
945
930
|
transportEntryMap,
|
|
946
931
|
transportContext,
|
|
947
|
-
getSubgraphSchema
|
|
932
|
+
getSubgraphSchema,
|
|
933
|
+
instrumentation
|
|
948
934
|
});
|
|
949
935
|
subgraphExecutorMap.set(subgraphName, executor);
|
|
950
936
|
return executor(subgraphExecReq);
|
|
@@ -959,14 +945,6 @@ function getOnSubgraphExecute({
|
|
|
959
945
|
executor
|
|
960
946
|
);
|
|
961
947
|
}
|
|
962
|
-
const originalExecutor = executor;
|
|
963
|
-
executor = (executionRequest2) => {
|
|
964
|
-
const subgraphInstrumentation = instrumentation$1()?.subgraphExecute;
|
|
965
|
-
return instrumentation.getInstrumented({ executionRequest: executionRequest2 }).asyncFn(
|
|
966
|
-
subgraphInstrumentation,
|
|
967
|
-
originalExecutor
|
|
968
|
-
)(executionRequest2);
|
|
969
|
-
};
|
|
970
948
|
return executor(executionRequest);
|
|
971
949
|
};
|
|
972
950
|
}
|
|
@@ -976,23 +954,16 @@ function wrapExecutorWithHooks({
|
|
|
976
954
|
subgraphName,
|
|
977
955
|
transportEntryMap,
|
|
978
956
|
getSubgraphSchema,
|
|
979
|
-
transportContext
|
|
957
|
+
transportContext,
|
|
958
|
+
instrumentation: instrumentation$1
|
|
980
959
|
}) {
|
|
981
|
-
|
|
960
|
+
function executorWithHooks(baseExecutionRequest) {
|
|
982
961
|
baseExecutionRequest.info = baseExecutionRequest.info || {};
|
|
983
962
|
baseExecutionRequest.info.executionRequest = baseExecutionRequest;
|
|
984
963
|
baseExecutionRequest.rootValue = {
|
|
985
964
|
executionRequest: baseExecutionRequest
|
|
986
965
|
};
|
|
987
|
-
const
|
|
988
|
-
let execReqLogger = transportContext?.logger;
|
|
989
|
-
if (execReqLogger) {
|
|
990
|
-
if (requestId) {
|
|
991
|
-
execReqLogger = execReqLogger.child({ requestId });
|
|
992
|
-
}
|
|
993
|
-
utils$1.loggerForExecutionRequest.set(baseExecutionRequest, execReqLogger);
|
|
994
|
-
}
|
|
995
|
-
execReqLogger = execReqLogger?.child?.({ subgraph: subgraphName });
|
|
966
|
+
const log = transportContext.log.child({ subgraph: subgraphName });
|
|
996
967
|
if (onSubgraphExecuteHooks.length === 0) {
|
|
997
968
|
return baseExecutor(baseExecutionRequest);
|
|
998
969
|
}
|
|
@@ -1016,11 +987,10 @@ function wrapExecutorWithHooks({
|
|
|
1016
987
|
},
|
|
1017
988
|
executor,
|
|
1018
989
|
setExecutor(newExecutor) {
|
|
1019
|
-
|
|
990
|
+
log?.debug("executor has been updated");
|
|
1020
991
|
executor = newExecutor;
|
|
1021
992
|
},
|
|
1022
|
-
|
|
1023
|
-
logger: execReqLogger
|
|
993
|
+
log
|
|
1024
994
|
}),
|
|
1025
995
|
onSubgraphExecuteDoneHooks
|
|
1026
996
|
),
|
|
@@ -1038,10 +1008,7 @@ function wrapExecutorWithHooks({
|
|
|
1038
1008
|
(onSubgraphExecuteDoneHook) => onSubgraphExecuteDoneHook({
|
|
1039
1009
|
result: currentResult,
|
|
1040
1010
|
setResult(newResult) {
|
|
1041
|
-
|
|
1042
|
-
"overriding result with: ",
|
|
1043
|
-
newResult
|
|
1044
|
-
);
|
|
1011
|
+
log?.debug("overriding result with: ", newResult);
|
|
1045
1012
|
currentResult = newResult;
|
|
1046
1013
|
}
|
|
1047
1014
|
}),
|
|
@@ -1075,10 +1042,7 @@ function wrapExecutorWithHooks({
|
|
|
1075
1042
|
(onNext) => onNext({
|
|
1076
1043
|
result: currentResult2,
|
|
1077
1044
|
setResult: (res) => {
|
|
1078
|
-
|
|
1079
|
-
"overriding result with: ",
|
|
1080
|
-
res
|
|
1081
|
-
);
|
|
1045
|
+
log?.debug("overriding result with: ", res);
|
|
1082
1046
|
currentResult2 = res;
|
|
1083
1047
|
}
|
|
1084
1048
|
})
|
|
@@ -1094,6 +1058,13 @@ function wrapExecutorWithHooks({
|
|
|
1094
1058
|
);
|
|
1095
1059
|
}
|
|
1096
1060
|
);
|
|
1061
|
+
}
|
|
1062
|
+
return function instrumentedExecutor(executionRequest) {
|
|
1063
|
+
const subgraphInstrument = instrumentation$1()?.subgraphExecute;
|
|
1064
|
+
return instrumentation.getInstrumented({ executionRequest, subgraphName }).asyncFn(
|
|
1065
|
+
subgraphInstrument,
|
|
1066
|
+
executorWithHooks
|
|
1067
|
+
)(executionRequest);
|
|
1097
1068
|
};
|
|
1098
1069
|
}
|
|
1099
1070
|
function compareSchemas(a, b) {
|
|
@@ -1121,18 +1092,10 @@ function compareSchemas(a, b) {
|
|
|
1121
1092
|
function compareSubgraphNames(name1, name2) {
|
|
1122
1093
|
return constantCase(name1) === constantCase(name2);
|
|
1123
1094
|
}
|
|
1124
|
-
function wrapMergedTypeResolver(originalResolver, typeName, onDelegationStageExecuteHooks,
|
|
1095
|
+
function wrapMergedTypeResolver(originalResolver, typeName, onDelegationStageExecuteHooks, log) {
|
|
1125
1096
|
return (object, context, info, subschema, selectionSet, key, type) => {
|
|
1126
|
-
let logger = baseLogger;
|
|
1127
|
-
let requestId;
|
|
1128
|
-
if (logger && context["request"]) {
|
|
1129
|
-
requestId = utils$1.requestIdByRequest.get(context["request"]);
|
|
1130
|
-
if (requestId) {
|
|
1131
|
-
logger = logger.child({ requestId });
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
1097
|
if (subschema.name) {
|
|
1135
|
-
|
|
1098
|
+
log = log.child({ subgraph: subschema.name });
|
|
1136
1099
|
}
|
|
1137
1100
|
let resolver = originalResolver;
|
|
1138
1101
|
function setResolver(newResolver) {
|
|
@@ -1150,8 +1113,7 @@ function wrapMergedTypeResolver(originalResolver, typeName, onDelegationStageExe
|
|
|
1150
1113
|
key,
|
|
1151
1114
|
typeName,
|
|
1152
1115
|
type,
|
|
1153
|
-
|
|
1154
|
-
logger,
|
|
1116
|
+
log,
|
|
1155
1117
|
resolver,
|
|
1156
1118
|
setResolver
|
|
1157
1119
|
});
|
|
@@ -1290,7 +1252,7 @@ class UnifiedGraphManager {
|
|
|
1290
1252
|
this.onDelegationPlanHooks = opts?.onDelegationPlanHooks || [];
|
|
1291
1253
|
this.onDelegationStageExecuteHooks = opts?.onDelegationStageExecuteHooks || [];
|
|
1292
1254
|
if (opts.pollingInterval != null) {
|
|
1293
|
-
opts.transportContext
|
|
1255
|
+
opts.transportContext.log.debug(
|
|
1294
1256
|
`Starting polling to Supergraph with interval ${millisecondsToStr(opts.pollingInterval)}`
|
|
1295
1257
|
);
|
|
1296
1258
|
}
|
|
@@ -1312,16 +1274,16 @@ class UnifiedGraphManager {
|
|
|
1312
1274
|
instrumentation;
|
|
1313
1275
|
ensureUnifiedGraph() {
|
|
1314
1276
|
if (this.polling$ == null && this.opts?.pollingInterval != null && this.lastLoadTime != null && Date.now() - this.lastLoadTime >= this.opts.pollingInterval) {
|
|
1315
|
-
this.opts?.transportContext
|
|
1277
|
+
this.opts?.transportContext.log.debug(`Polling Supergraph`);
|
|
1316
1278
|
this.polling$ = promiseHelpers.handleMaybePromise(
|
|
1317
1279
|
() => this.getAndSetUnifiedGraph(),
|
|
1318
1280
|
() => {
|
|
1319
1281
|
this.polling$ = void 0;
|
|
1320
1282
|
},
|
|
1321
1283
|
(err) => {
|
|
1322
|
-
this.opts.transportContext
|
|
1323
|
-
|
|
1324
|
-
|
|
1284
|
+
this.opts.transportContext.log.error(
|
|
1285
|
+
err,
|
|
1286
|
+
"Failed to poll Supergraph"
|
|
1325
1287
|
);
|
|
1326
1288
|
this.polling$ = void 0;
|
|
1327
1289
|
}
|
|
@@ -1329,18 +1291,20 @@ class UnifiedGraphManager {
|
|
|
1329
1291
|
}
|
|
1330
1292
|
if (!this.unifiedGraph) {
|
|
1331
1293
|
if (!this.initialUnifiedGraph$) {
|
|
1332
|
-
this.opts?.transportContext
|
|
1294
|
+
this.opts?.transportContext.log.debug(
|
|
1333
1295
|
"Fetching the initial Supergraph"
|
|
1334
1296
|
);
|
|
1335
|
-
if (this.opts.transportContext
|
|
1336
|
-
this.opts.transportContext
|
|
1337
|
-
|
|
1297
|
+
if (this.opts.transportContext.cache) {
|
|
1298
|
+
this.opts.transportContext.log.debug(
|
|
1299
|
+
{ key: UNIFIEDGRAPH_CACHE_KEY },
|
|
1300
|
+
"Searching for Supergraph in cache..."
|
|
1338
1301
|
);
|
|
1339
1302
|
this.initialUnifiedGraph$ = promiseHelpers.handleMaybePromise(
|
|
1340
|
-
() => this.opts.transportContext
|
|
1303
|
+
() => this.opts.transportContext.cache?.get(UNIFIEDGRAPH_CACHE_KEY),
|
|
1341
1304
|
(cachedUnifiedGraph) => {
|
|
1342
1305
|
if (cachedUnifiedGraph) {
|
|
1343
|
-
this.opts.transportContext
|
|
1306
|
+
this.opts.transportContext.log.debug(
|
|
1307
|
+
{ key: UNIFIEDGRAPH_CACHE_KEY },
|
|
1344
1308
|
"Found Supergraph in cache"
|
|
1345
1309
|
);
|
|
1346
1310
|
return this.handleLoadedUnifiedGraph(cachedUnifiedGraph, true);
|
|
@@ -1358,7 +1322,8 @@ class UnifiedGraphManager {
|
|
|
1358
1322
|
() => this.initialUnifiedGraph$,
|
|
1359
1323
|
(v) => {
|
|
1360
1324
|
this.initialUnifiedGraph$ = void 0;
|
|
1361
|
-
this.opts.transportContext
|
|
1325
|
+
this.opts.transportContext.log.debug(
|
|
1326
|
+
{ key: UNIFIEDGRAPH_CACHE_KEY },
|
|
1362
1327
|
"Initial Supergraph fetched"
|
|
1363
1328
|
);
|
|
1364
1329
|
return v;
|
|
@@ -1373,7 +1338,7 @@ class UnifiedGraphManager {
|
|
|
1373
1338
|
handleLoadedUnifiedGraph(loadedUnifiedGraph, doNotCache) {
|
|
1374
1339
|
if (loadedUnifiedGraph != null) {
|
|
1375
1340
|
if (this.lastLoadedUnifiedGraph != null && compareSchemas(loadedUnifiedGraph, this.lastLoadedUnifiedGraph)) {
|
|
1376
|
-
this.opts.transportContext
|
|
1341
|
+
this.opts.transportContext.log.debug(
|
|
1377
1342
|
"Supergraph has not been changed, skipping..."
|
|
1378
1343
|
);
|
|
1379
1344
|
this.lastLoadTime = Date.now();
|
|
@@ -1399,13 +1364,14 @@ class UnifiedGraphManager {
|
|
|
1399
1364
|
// NOTE: we default to 60s because Cloudflare KV TTL does not accept anything less
|
|
1400
1365
|
60
|
|
1401
1366
|
);
|
|
1402
|
-
this.opts.transportContext.
|
|
1403
|
-
|
|
1367
|
+
this.opts.transportContext.log.debug(
|
|
1368
|
+
{ ttl, key: UNIFIEDGRAPH_CACHE_KEY },
|
|
1369
|
+
"Caching Supergraph"
|
|
1404
1370
|
);
|
|
1405
|
-
const logCacheSetError = (
|
|
1406
|
-
this.opts.transportContext
|
|
1407
|
-
|
|
1408
|
-
|
|
1371
|
+
const logCacheSetError = (err) => {
|
|
1372
|
+
this.opts.transportContext.log.debug(
|
|
1373
|
+
{ err, ttl, key: UNIFIEDGRAPH_CACHE_KEY },
|
|
1374
|
+
"Unable to cache Supergraph"
|
|
1409
1375
|
);
|
|
1410
1376
|
};
|
|
1411
1377
|
try {
|
|
@@ -1422,10 +1388,10 @@ class UnifiedGraphManager {
|
|
|
1422
1388
|
} catch (e) {
|
|
1423
1389
|
logCacheSetError(e);
|
|
1424
1390
|
}
|
|
1425
|
-
} catch (
|
|
1426
|
-
this.opts.transportContext.
|
|
1427
|
-
|
|
1428
|
-
|
|
1391
|
+
} catch (err) {
|
|
1392
|
+
this.opts.transportContext.log.error(
|
|
1393
|
+
err,
|
|
1394
|
+
"Failed to initiate caching of Supergraph"
|
|
1429
1395
|
);
|
|
1430
1396
|
}
|
|
1431
1397
|
}
|
|
@@ -1450,7 +1416,7 @@ class UnifiedGraphManager {
|
|
|
1450
1416
|
onDelegationPlanHooks: this.onDelegationPlanHooks,
|
|
1451
1417
|
onDelegationStageExecuteHooks: this.onDelegationStageExecuteHooks,
|
|
1452
1418
|
onDelegateHooks: this.opts.onDelegateHooks,
|
|
1453
|
-
|
|
1419
|
+
log: this.opts.transportContext.log
|
|
1454
1420
|
});
|
|
1455
1421
|
const transportExecutorStack = new disposablestack.AsyncDisposableStack();
|
|
1456
1422
|
const onSubgraphExecute = getOnSubgraphExecute({
|
|
@@ -1489,7 +1455,7 @@ class UnifiedGraphManager {
|
|
|
1489
1455
|
}
|
|
1490
1456
|
}
|
|
1491
1457
|
);
|
|
1492
|
-
this.opts.transportContext
|
|
1458
|
+
this.opts.transportContext.log.debug(
|
|
1493
1459
|
"Supergraph has been changed, updating..."
|
|
1494
1460
|
);
|
|
1495
1461
|
}
|
|
@@ -1501,9 +1467,9 @@ class UnifiedGraphManager {
|
|
|
1501
1467
|
},
|
|
1502
1468
|
(err) => {
|
|
1503
1469
|
this.disposeReason = void 0;
|
|
1504
|
-
this.opts.transportContext
|
|
1505
|
-
|
|
1506
|
-
|
|
1470
|
+
this.opts.transportContext.log.error(
|
|
1471
|
+
err,
|
|
1472
|
+
"Failed to dispose the existing transports and executors"
|
|
1507
1473
|
);
|
|
1508
1474
|
return this.unifiedGraph;
|
|
1509
1475
|
}
|
|
@@ -1523,10 +1489,7 @@ class UnifiedGraphManager {
|
|
|
1523
1489
|
() => this.opts.getUnifiedGraph(this.opts.transportContext || {}),
|
|
1524
1490
|
(loadedUnifiedGraph) => this.handleLoadedUnifiedGraph(loadedUnifiedGraph),
|
|
1525
1491
|
(err) => {
|
|
1526
|
-
this.opts.transportContext
|
|
1527
|
-
"Failed to load Supergraph",
|
|
1528
|
-
err
|
|
1529
|
-
);
|
|
1492
|
+
this.opts.transportContext.log.error(err, "Failed to load Supergraph");
|
|
1530
1493
|
this.lastLoadTime = Date.now();
|
|
1531
1494
|
this.disposeReason = void 0;
|
|
1532
1495
|
this.polling$ = void 0;
|
|
@@ -1627,7 +1590,7 @@ function getExecutorForUnifiedGraph(opts) {
|
|
|
1627
1590
|
() => unifiedGraphManager.getContext(execReq.context),
|
|
1628
1591
|
(context) => {
|
|
1629
1592
|
function handleExecutor(executor) {
|
|
1630
|
-
opts?.transportContext
|
|
1593
|
+
opts?.transportContext.log.debug(
|
|
1631
1594
|
"Executing request on unified graph",
|
|
1632
1595
|
() => graphql.print(execReq.document)
|
|
1633
1596
|
);
|
|
@@ -1643,7 +1606,7 @@ function getExecutorForUnifiedGraph(opts) {
|
|
|
1643
1606
|
return promiseHelpers.handleMaybePromise(
|
|
1644
1607
|
() => unifiedGraphManager.getUnifiedGraph(),
|
|
1645
1608
|
(unifiedGraph) => {
|
|
1646
|
-
opts?.transportContext
|
|
1609
|
+
opts?.transportContext.log.debug(
|
|
1647
1610
|
"Executing request on unified graph",
|
|
1648
1611
|
() => graphql.print(execReq.document)
|
|
1649
1612
|
);
|
|
@@ -1663,9 +1626,7 @@ function getExecutorForUnifiedGraph(opts) {
|
|
|
1663
1626
|
enumerable: true,
|
|
1664
1627
|
get() {
|
|
1665
1628
|
return function unifiedGraphExecutorDispose() {
|
|
1666
|
-
opts?.transportContext
|
|
1667
|
-
"Disposing unified graph executor"
|
|
1668
|
-
);
|
|
1629
|
+
opts?.transportContext.log.debug("Disposing unified graph executor");
|
|
1669
1630
|
return unifiedGraphManager[disposablestack.DisposableSymbols.asyncDispose]();
|
|
1670
1631
|
};
|
|
1671
1632
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as _graphql_tools_utils from '@graphql-tools/utils';
|
|
2
2
|
import { ExecutionRequest, TypeSource, IResolvers, Executor, MaybePromise as MaybePromise$1, Maybe, DisposableExecutor } from '@graphql-tools/utils';
|
|
3
|
+
import { Logger } from '@graphql-hive/logger';
|
|
3
4
|
import { TransportEntry, TransportContext, Transport } from '@graphql-mesh/transport-common';
|
|
4
5
|
export { TransportEntry, TransportGetSubgraphExecutor, TransportGetSubgraphExecutorOptions } from '@graphql-mesh/transport-common';
|
|
5
|
-
import { OnDelegateHook, Logger } from '@graphql-mesh/types';
|
|
6
6
|
import { Subschema, DelegationPlanBuilder, MergedTypeResolver, SubschemaConfig } from '@graphql-tools/delegate';
|
|
7
7
|
import * as graphql from 'graphql';
|
|
8
8
|
import { GraphQLSchema, DocumentNode, ExecutionResult, GraphQLError, FragmentDefinitionNode, SelectionNode, SelectionSetNode } from 'graphql';
|
|
9
9
|
import { GraphQLResolveInfo, GraphQLOutputType } from 'graphql/type';
|
|
10
|
+
import { OnDelegateHook } from '@graphql-mesh/types';
|
|
10
11
|
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
11
12
|
import { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
12
13
|
|
|
@@ -23,7 +24,7 @@ interface UnifiedGraphHandlerOpts {
|
|
|
23
24
|
onDelegationPlanHooks?: OnDelegationPlanHook<any>[];
|
|
24
25
|
onDelegationStageExecuteHooks?: OnDelegationStageExecuteHook<any>[];
|
|
25
26
|
onDelegateHooks?: OnDelegateHook<unknown>[];
|
|
26
|
-
|
|
27
|
+
log: Logger;
|
|
27
28
|
}
|
|
28
29
|
interface UnifiedGraphHandlerResult {
|
|
29
30
|
unifiedGraph: GraphQLSchema;
|
|
@@ -40,7 +41,7 @@ interface UnifiedGraphManagerOptions<TContext> {
|
|
|
40
41
|
pollingInterval?: number;
|
|
41
42
|
additionalTypeDefs?: TypeSource;
|
|
42
43
|
additionalResolvers?: IResolvers<unknown, TContext> | IResolvers<unknown, TContext>[];
|
|
43
|
-
transportContext
|
|
44
|
+
transportContext: TransportContext;
|
|
44
45
|
onSubgraphExecuteHooks?: OnSubgraphExecuteHook<TContext>[];
|
|
45
46
|
onDelegateHooks?: OnDelegateHook<unknown>[];
|
|
46
47
|
onDelegationPlanHooks?: OnDelegationPlanHook<TContext>[];
|
|
@@ -59,6 +60,7 @@ type Instrumentation = {
|
|
|
59
60
|
*/
|
|
60
61
|
subgraphExecute?: (payload: {
|
|
61
62
|
executionRequest: ExecutionRequest;
|
|
63
|
+
subgraphName: string;
|
|
62
64
|
}, wrapped: () => MaybePromise<void>) => MaybePromise<void>;
|
|
63
65
|
};
|
|
64
66
|
declare class UnifiedGraphManager<TContext> implements AsyncDisposable {
|
|
@@ -106,7 +108,7 @@ declare const subgraphNameByExecutionRequest: WeakMap<ExecutionRequest<any, any,
|
|
|
106
108
|
declare function getOnSubgraphExecute({ onSubgraphExecuteHooks, transportContext, transportEntryMap, getSubgraphSchema, transportExecutorStack, transports, getDisposeReason, batch, instrumentation, }: {
|
|
107
109
|
onSubgraphExecuteHooks: OnSubgraphExecuteHook[];
|
|
108
110
|
transports?: Transports;
|
|
109
|
-
transportContext
|
|
111
|
+
transportContext: TransportContext;
|
|
110
112
|
transportEntryMap: Record<string, TransportEntry>;
|
|
111
113
|
getSubgraphSchema(subgraphName: string): GraphQLSchema;
|
|
112
114
|
transportExecutorStack: AsyncDisposableStack;
|
|
@@ -120,7 +122,8 @@ interface WrapExecuteWithHooksOptions {
|
|
|
120
122
|
subgraphName: string;
|
|
121
123
|
transportEntryMap?: Record<string, TransportEntry>;
|
|
122
124
|
getSubgraphSchema: (subgraphName: string) => GraphQLSchema;
|
|
123
|
-
transportContext
|
|
125
|
+
transportContext: TransportContext;
|
|
126
|
+
instrumentation: () => Instrumentation | undefined;
|
|
124
127
|
}
|
|
125
128
|
declare module 'graphql' {
|
|
126
129
|
interface GraphQLResolveInfo {
|
|
@@ -131,7 +134,7 @@ declare module 'graphql' {
|
|
|
131
134
|
* This function wraps the executor created by the transport package
|
|
132
135
|
* with `onSubgraphExecuteHooks` to hook into the execution phase of subgraphs
|
|
133
136
|
*/
|
|
134
|
-
declare function wrapExecutorWithHooks({ executor: baseExecutor, onSubgraphExecuteHooks, subgraphName, transportEntryMap, getSubgraphSchema, transportContext, }: WrapExecuteWithHooksOptions): Executor;
|
|
137
|
+
declare function wrapExecutorWithHooks({ executor: baseExecutor, onSubgraphExecuteHooks, subgraphName, transportEntryMap, getSubgraphSchema, transportContext, instrumentation, }: WrapExecuteWithHooksOptions): Executor;
|
|
135
138
|
interface UnifiedGraphPlugin<TContext> {
|
|
136
139
|
onSubgraphExecute?: OnSubgraphExecuteHook<TContext>;
|
|
137
140
|
onDelegationPlan?: OnDelegationPlanHook<TContext>;
|
|
@@ -146,8 +149,7 @@ interface OnSubgraphExecutePayload<TContext> {
|
|
|
146
149
|
setExecutionRequest(executionRequest: ExecutionRequest): void;
|
|
147
150
|
executor: Executor;
|
|
148
151
|
setExecutor(executor: Executor): void;
|
|
149
|
-
|
|
150
|
-
logger?: Logger;
|
|
152
|
+
log: Logger;
|
|
151
153
|
}
|
|
152
154
|
interface OnSubgraphExecuteDonePayload {
|
|
153
155
|
result: AsyncIterable<ExecutionResult> | ExecutionResult;
|
|
@@ -174,8 +176,7 @@ interface OnDelegationPlanHookPayload<TContext> {
|
|
|
174
176
|
fragments: Record<string, FragmentDefinitionNode>;
|
|
175
177
|
fieldNodes: SelectionNode[];
|
|
176
178
|
context: TContext;
|
|
177
|
-
|
|
178
|
-
logger?: Logger;
|
|
179
|
+
log: Logger;
|
|
179
180
|
info?: GraphQLResolveInfo;
|
|
180
181
|
delegationPlanBuilder: DelegationPlanBuilder;
|
|
181
182
|
setDelegationPlanBuilder(delegationPlanBuilder: DelegationPlanBuilder): void;
|
|
@@ -198,8 +199,7 @@ interface OnDelegationStageExecutePayload<TContext> {
|
|
|
198
199
|
resolver: MergedTypeResolver<TContext>;
|
|
199
200
|
setResolver: (resolver: MergedTypeResolver<TContext>) => void;
|
|
200
201
|
typeName: string;
|
|
201
|
-
|
|
202
|
-
logger?: Logger;
|
|
202
|
+
log: Logger;
|
|
203
203
|
}
|
|
204
204
|
type OnDelegationStageExecuteDoneHook = (payload: OnDelegationStageExecuteDonePayload) => void;
|
|
205
205
|
interface OnDelegationStageExecuteDonePayload {
|
|
@@ -208,7 +208,7 @@ interface OnDelegationStageExecuteDonePayload {
|
|
|
208
208
|
}
|
|
209
209
|
declare function compareSchemas(a: DocumentNode | string | GraphQLSchema, b: DocumentNode | string | GraphQLSchema): boolean;
|
|
210
210
|
declare function compareSubgraphNames(name1: string, name2: string): boolean;
|
|
211
|
-
declare function wrapMergedTypeResolver<TContext extends Record<string, any>>(originalResolver: MergedTypeResolver<TContext>, typeName: string, onDelegationStageExecuteHooks: OnDelegationStageExecuteHook<TContext>[],
|
|
211
|
+
declare function wrapMergedTypeResolver<TContext extends Record<string, any>>(originalResolver: MergedTypeResolver<TContext>, typeName: string, onDelegationStageExecuteHooks: OnDelegationStageExecuteHook<TContext>[], log: Logger): MergedTypeResolver<TContext>;
|
|
212
212
|
declare function millisecondsToStr(milliseconds: number): string;
|
|
213
213
|
declare function getTransportEntryMapUsingFusionAndFederationDirectives(unifiedGraph: GraphQLSchema, transportEntryAdditions?: TransportEntryAdditions): Record<string, TransportEntry<Record<string, any>>>;
|
|
214
214
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import * as _graphql_tools_utils from '@graphql-tools/utils';
|
|
2
2
|
import { ExecutionRequest, TypeSource, IResolvers, Executor, MaybePromise as MaybePromise$1, Maybe, DisposableExecutor } from '@graphql-tools/utils';
|
|
3
|
+
import { Logger } from '@graphql-hive/logger';
|
|
3
4
|
import { TransportEntry, TransportContext, Transport } from '@graphql-mesh/transport-common';
|
|
4
5
|
export { TransportEntry, TransportGetSubgraphExecutor, TransportGetSubgraphExecutorOptions } from '@graphql-mesh/transport-common';
|
|
5
|
-
import { OnDelegateHook, Logger } from '@graphql-mesh/types';
|
|
6
6
|
import { Subschema, DelegationPlanBuilder, MergedTypeResolver, SubschemaConfig } from '@graphql-tools/delegate';
|
|
7
7
|
import * as graphql from 'graphql';
|
|
8
8
|
import { GraphQLSchema, DocumentNode, ExecutionResult, GraphQLError, FragmentDefinitionNode, SelectionNode, SelectionSetNode } from 'graphql';
|
|
9
9
|
import { GraphQLResolveInfo, GraphQLOutputType } from 'graphql/type';
|
|
10
|
+
import { OnDelegateHook } from '@graphql-mesh/types';
|
|
10
11
|
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
11
12
|
import { MaybePromise } from '@whatwg-node/promise-helpers';
|
|
12
13
|
|
|
@@ -23,7 +24,7 @@ interface UnifiedGraphHandlerOpts {
|
|
|
23
24
|
onDelegationPlanHooks?: OnDelegationPlanHook<any>[];
|
|
24
25
|
onDelegationStageExecuteHooks?: OnDelegationStageExecuteHook<any>[];
|
|
25
26
|
onDelegateHooks?: OnDelegateHook<unknown>[];
|
|
26
|
-
|
|
27
|
+
log: Logger;
|
|
27
28
|
}
|
|
28
29
|
interface UnifiedGraphHandlerResult {
|
|
29
30
|
unifiedGraph: GraphQLSchema;
|
|
@@ -40,7 +41,7 @@ interface UnifiedGraphManagerOptions<TContext> {
|
|
|
40
41
|
pollingInterval?: number;
|
|
41
42
|
additionalTypeDefs?: TypeSource;
|
|
42
43
|
additionalResolvers?: IResolvers<unknown, TContext> | IResolvers<unknown, TContext>[];
|
|
43
|
-
transportContext
|
|
44
|
+
transportContext: TransportContext;
|
|
44
45
|
onSubgraphExecuteHooks?: OnSubgraphExecuteHook<TContext>[];
|
|
45
46
|
onDelegateHooks?: OnDelegateHook<unknown>[];
|
|
46
47
|
onDelegationPlanHooks?: OnDelegationPlanHook<TContext>[];
|
|
@@ -59,6 +60,7 @@ type Instrumentation = {
|
|
|
59
60
|
*/
|
|
60
61
|
subgraphExecute?: (payload: {
|
|
61
62
|
executionRequest: ExecutionRequest;
|
|
63
|
+
subgraphName: string;
|
|
62
64
|
}, wrapped: () => MaybePromise<void>) => MaybePromise<void>;
|
|
63
65
|
};
|
|
64
66
|
declare class UnifiedGraphManager<TContext> implements AsyncDisposable {
|
|
@@ -106,7 +108,7 @@ declare const subgraphNameByExecutionRequest: WeakMap<ExecutionRequest<any, any,
|
|
|
106
108
|
declare function getOnSubgraphExecute({ onSubgraphExecuteHooks, transportContext, transportEntryMap, getSubgraphSchema, transportExecutorStack, transports, getDisposeReason, batch, instrumentation, }: {
|
|
107
109
|
onSubgraphExecuteHooks: OnSubgraphExecuteHook[];
|
|
108
110
|
transports?: Transports;
|
|
109
|
-
transportContext
|
|
111
|
+
transportContext: TransportContext;
|
|
110
112
|
transportEntryMap: Record<string, TransportEntry>;
|
|
111
113
|
getSubgraphSchema(subgraphName: string): GraphQLSchema;
|
|
112
114
|
transportExecutorStack: AsyncDisposableStack;
|
|
@@ -120,7 +122,8 @@ interface WrapExecuteWithHooksOptions {
|
|
|
120
122
|
subgraphName: string;
|
|
121
123
|
transportEntryMap?: Record<string, TransportEntry>;
|
|
122
124
|
getSubgraphSchema: (subgraphName: string) => GraphQLSchema;
|
|
123
|
-
transportContext
|
|
125
|
+
transportContext: TransportContext;
|
|
126
|
+
instrumentation: () => Instrumentation | undefined;
|
|
124
127
|
}
|
|
125
128
|
declare module 'graphql' {
|
|
126
129
|
interface GraphQLResolveInfo {
|
|
@@ -131,7 +134,7 @@ declare module 'graphql' {
|
|
|
131
134
|
* This function wraps the executor created by the transport package
|
|
132
135
|
* with `onSubgraphExecuteHooks` to hook into the execution phase of subgraphs
|
|
133
136
|
*/
|
|
134
|
-
declare function wrapExecutorWithHooks({ executor: baseExecutor, onSubgraphExecuteHooks, subgraphName, transportEntryMap, getSubgraphSchema, transportContext, }: WrapExecuteWithHooksOptions): Executor;
|
|
137
|
+
declare function wrapExecutorWithHooks({ executor: baseExecutor, onSubgraphExecuteHooks, subgraphName, transportEntryMap, getSubgraphSchema, transportContext, instrumentation, }: WrapExecuteWithHooksOptions): Executor;
|
|
135
138
|
interface UnifiedGraphPlugin<TContext> {
|
|
136
139
|
onSubgraphExecute?: OnSubgraphExecuteHook<TContext>;
|
|
137
140
|
onDelegationPlan?: OnDelegationPlanHook<TContext>;
|
|
@@ -146,8 +149,7 @@ interface OnSubgraphExecutePayload<TContext> {
|
|
|
146
149
|
setExecutionRequest(executionRequest: ExecutionRequest): void;
|
|
147
150
|
executor: Executor;
|
|
148
151
|
setExecutor(executor: Executor): void;
|
|
149
|
-
|
|
150
|
-
logger?: Logger;
|
|
152
|
+
log: Logger;
|
|
151
153
|
}
|
|
152
154
|
interface OnSubgraphExecuteDonePayload {
|
|
153
155
|
result: AsyncIterable<ExecutionResult> | ExecutionResult;
|
|
@@ -174,8 +176,7 @@ interface OnDelegationPlanHookPayload<TContext> {
|
|
|
174
176
|
fragments: Record<string, FragmentDefinitionNode>;
|
|
175
177
|
fieldNodes: SelectionNode[];
|
|
176
178
|
context: TContext;
|
|
177
|
-
|
|
178
|
-
logger?: Logger;
|
|
179
|
+
log: Logger;
|
|
179
180
|
info?: GraphQLResolveInfo;
|
|
180
181
|
delegationPlanBuilder: DelegationPlanBuilder;
|
|
181
182
|
setDelegationPlanBuilder(delegationPlanBuilder: DelegationPlanBuilder): void;
|
|
@@ -198,8 +199,7 @@ interface OnDelegationStageExecutePayload<TContext> {
|
|
|
198
199
|
resolver: MergedTypeResolver<TContext>;
|
|
199
200
|
setResolver: (resolver: MergedTypeResolver<TContext>) => void;
|
|
200
201
|
typeName: string;
|
|
201
|
-
|
|
202
|
-
logger?: Logger;
|
|
202
|
+
log: Logger;
|
|
203
203
|
}
|
|
204
204
|
type OnDelegationStageExecuteDoneHook = (payload: OnDelegationStageExecuteDonePayload) => void;
|
|
205
205
|
interface OnDelegationStageExecuteDonePayload {
|
|
@@ -208,7 +208,7 @@ interface OnDelegationStageExecuteDonePayload {
|
|
|
208
208
|
}
|
|
209
209
|
declare function compareSchemas(a: DocumentNode | string | GraphQLSchema, b: DocumentNode | string | GraphQLSchema): boolean;
|
|
210
210
|
declare function compareSubgraphNames(name1: string, name2: string): boolean;
|
|
211
|
-
declare function wrapMergedTypeResolver<TContext extends Record<string, any>>(originalResolver: MergedTypeResolver<TContext>, typeName: string, onDelegationStageExecuteHooks: OnDelegationStageExecuteHook<TContext>[],
|
|
211
|
+
declare function wrapMergedTypeResolver<TContext extends Record<string, any>>(originalResolver: MergedTypeResolver<TContext>, typeName: string, onDelegationStageExecuteHooks: OnDelegationStageExecuteHook<TContext>[], log: Logger): MergedTypeResolver<TContext>;
|
|
212
212
|
declare function millisecondsToStr(milliseconds: number): string;
|
|
213
213
|
declare function getTransportEntryMapUsingFusionAndFederationDirectives(unifiedGraph: GraphQLSchema, transportEntryAdditions?: TransportEntryAdditions): Record<string, TransportEntry<Record<string, any>>>;
|
|
214
214
|
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { getInstrumented } from '@envelop/instrumentation';
|
|
2
|
+
import { loggerForRequest } from '@graphql-hive/logger/request';
|
|
2
3
|
import { defaultPrintFn, createDefaultExecutor } from '@graphql-mesh/transport-common';
|
|
3
|
-
import { resolveAdditionalResolversWithoutImport, getInContextSDK,
|
|
4
|
+
import { resolveAdditionalResolversWithoutImport, getInContextSDK, isDisposable, iterateAsync, dispose } from '@graphql-mesh/utils';
|
|
4
5
|
import { getBatchingExecutor } from '@graphql-tools/batch-execute';
|
|
5
|
-
import { getDirectiveExtensions, mapSchema, MapperKind, astFromField, memoize1, asArray, getDocumentNodeFromSchema,
|
|
6
|
+
import { getDirectiveExtensions, mapSchema, MapperKind, astFromField, memoize1, asArray, getDocumentNodeFromSchema, isDocumentNode, printSchemaWithDirectives, mergeDeep, isAsyncIterable, createGraphQLError } from '@graphql-tools/utils';
|
|
6
7
|
import { handleMaybePromise, mapAsyncIterator, isPromise } from '@whatwg-node/promise-helpers';
|
|
7
8
|
import { isInterfaceType, Kind, isObjectType, typeFromAST, isOutputType, GraphQLSchema, GraphQLDirective, parseType, visit, GraphQLString, DirectiveLocation, isEnumType, isSchema, buildSchema, buildASTSchema, print } from 'graphql';
|
|
9
|
+
import { LegacyLogger } from '@graphql-hive/logger';
|
|
8
10
|
import { getStitchedSchemaFromSupergraphSdl } from '@graphql-tools/federation';
|
|
9
11
|
import { mergeTypeDefs } from '@graphql-tools/merge';
|
|
10
12
|
import { createMergedTypeResolver } from '@graphql-tools/stitch';
|
|
@@ -595,7 +597,7 @@ const handleFederationSupergraph = function({
|
|
|
595
597
|
onDelegateHooks,
|
|
596
598
|
additionalTypeDefs: additionalTypeDefsFromConfig = [],
|
|
597
599
|
additionalResolvers: additionalResolversFromConfig = [],
|
|
598
|
-
|
|
600
|
+
log: rootLog
|
|
599
601
|
}) {
|
|
600
602
|
const additionalTypeDefs = [...asArray(additionalTypeDefsFromConfig)];
|
|
601
603
|
const additionalResolvers = [...asArray(additionalResolversFromConfig)];
|
|
@@ -658,7 +660,7 @@ const handleFederationSupergraph = function({
|
|
|
658
660
|
originalResolver,
|
|
659
661
|
typeName,
|
|
660
662
|
onDelegationStageExecuteHooks,
|
|
661
|
-
|
|
663
|
+
rootLog
|
|
662
664
|
);
|
|
663
665
|
}
|
|
664
666
|
}
|
|
@@ -703,7 +705,7 @@ const handleFederationSupergraph = function({
|
|
|
703
705
|
executableUnifiedGraph,
|
|
704
706
|
// @ts-expect-error Legacy Mesh RawSource is not compatible with new Mesh
|
|
705
707
|
subschemas,
|
|
706
|
-
|
|
708
|
+
LegacyLogger.from(rootLog),
|
|
707
709
|
onDelegateHooks || []
|
|
708
710
|
);
|
|
709
711
|
const stitchingInfo = executableUnifiedGraph.extensions?.["stitchingInfo"];
|
|
@@ -718,16 +720,9 @@ const handleFederationSupergraph = function({
|
|
|
718
720
|
delegationPlanBuilder = newDelegationPlanBuilder;
|
|
719
721
|
}
|
|
720
722
|
const onDelegationPlanDoneHooks = [];
|
|
721
|
-
let
|
|
722
|
-
let requestId;
|
|
723
|
-
if (context?.request) {
|
|
724
|
-
requestId = requestIdByRequest.get(context.request);
|
|
725
|
-
if (requestId) {
|
|
726
|
-
currentLogger = currentLogger?.child({ requestId });
|
|
727
|
-
}
|
|
728
|
-
}
|
|
723
|
+
let log = context.log;
|
|
729
724
|
if (sourceSubschema.name) {
|
|
730
|
-
|
|
725
|
+
log = log.child({
|
|
731
726
|
subgraph: sourceSubschema.name
|
|
732
727
|
});
|
|
733
728
|
}
|
|
@@ -740,7 +735,7 @@ const handleFederationSupergraph = function({
|
|
|
740
735
|
variables,
|
|
741
736
|
fragments,
|
|
742
737
|
fieldNodes,
|
|
743
|
-
|
|
738
|
+
log,
|
|
744
739
|
context,
|
|
745
740
|
info,
|
|
746
741
|
delegationPlanBuilder,
|
|
@@ -833,13 +828,7 @@ function getTransportExecutor({
|
|
|
833
828
|
getDisposeReason
|
|
834
829
|
}) {
|
|
835
830
|
const kind = transportEntry?.kind || "";
|
|
836
|
-
|
|
837
|
-
if (logger) {
|
|
838
|
-
if (subgraphName) {
|
|
839
|
-
logger = logger.child({ subgraph: subgraphName });
|
|
840
|
-
}
|
|
841
|
-
logger?.debug(`Loading transport "${kind}"`);
|
|
842
|
-
}
|
|
831
|
+
transportContext.log.debug(`Loading transport "${kind}"`);
|
|
843
832
|
return handleMaybePromise(
|
|
844
833
|
() => typeof transports === "function" ? transports(kind) : transports[kind],
|
|
845
834
|
(transport) => {
|
|
@@ -888,7 +877,7 @@ function getTransportExecutor({
|
|
|
888
877
|
const subgraphNameByExecutionRequest = /* @__PURE__ */ new WeakMap();
|
|
889
878
|
function getOnSubgraphExecute({
|
|
890
879
|
onSubgraphExecuteHooks,
|
|
891
|
-
transportContext
|
|
880
|
+
transportContext,
|
|
892
881
|
transportEntryMap,
|
|
893
882
|
getSubgraphSchema,
|
|
894
883
|
transportExecutorStack,
|
|
@@ -902,19 +891,15 @@ function getOnSubgraphExecute({
|
|
|
902
891
|
subgraphNameByExecutionRequest.set(executionRequest, subgraphName);
|
|
903
892
|
let executor = subgraphExecutorMap.get(subgraphName);
|
|
904
893
|
if (executor == null) {
|
|
905
|
-
let
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
logger = logger.child({ requestId });
|
|
912
|
-
}
|
|
913
|
-
if (subgraphName) {
|
|
914
|
-
logger = logger.child({ subgraph: subgraphName });
|
|
915
|
-
}
|
|
916
|
-
logger.debug(`Initializing executor`);
|
|
894
|
+
let log = executionRequest.context?.request ? loggerForRequest(
|
|
895
|
+
transportContext.log,
|
|
896
|
+
executionRequest.context.request
|
|
897
|
+
) : transportContext.log;
|
|
898
|
+
if (subgraphName) {
|
|
899
|
+
log = log.child({ subgraph: subgraphName });
|
|
917
900
|
}
|
|
901
|
+
transportContext.log = log;
|
|
902
|
+
log.debug("Initializing executor");
|
|
918
903
|
executor = function lazyExecutor(subgraphExecReq) {
|
|
919
904
|
return handleMaybePromise(
|
|
920
905
|
() => (
|
|
@@ -942,7 +927,8 @@ function getOnSubgraphExecute({
|
|
|
942
927
|
subgraphName,
|
|
943
928
|
transportEntryMap,
|
|
944
929
|
transportContext,
|
|
945
|
-
getSubgraphSchema
|
|
930
|
+
getSubgraphSchema,
|
|
931
|
+
instrumentation
|
|
946
932
|
});
|
|
947
933
|
subgraphExecutorMap.set(subgraphName, executor);
|
|
948
934
|
return executor(subgraphExecReq);
|
|
@@ -957,14 +943,6 @@ function getOnSubgraphExecute({
|
|
|
957
943
|
executor
|
|
958
944
|
);
|
|
959
945
|
}
|
|
960
|
-
const originalExecutor = executor;
|
|
961
|
-
executor = (executionRequest2) => {
|
|
962
|
-
const subgraphInstrumentation = instrumentation()?.subgraphExecute;
|
|
963
|
-
return getInstrumented({ executionRequest: executionRequest2 }).asyncFn(
|
|
964
|
-
subgraphInstrumentation,
|
|
965
|
-
originalExecutor
|
|
966
|
-
)(executionRequest2);
|
|
967
|
-
};
|
|
968
946
|
return executor(executionRequest);
|
|
969
947
|
};
|
|
970
948
|
}
|
|
@@ -974,23 +952,16 @@ function wrapExecutorWithHooks({
|
|
|
974
952
|
subgraphName,
|
|
975
953
|
transportEntryMap,
|
|
976
954
|
getSubgraphSchema,
|
|
977
|
-
transportContext
|
|
955
|
+
transportContext,
|
|
956
|
+
instrumentation
|
|
978
957
|
}) {
|
|
979
|
-
|
|
958
|
+
function executorWithHooks(baseExecutionRequest) {
|
|
980
959
|
baseExecutionRequest.info = baseExecutionRequest.info || {};
|
|
981
960
|
baseExecutionRequest.info.executionRequest = baseExecutionRequest;
|
|
982
961
|
baseExecutionRequest.rootValue = {
|
|
983
962
|
executionRequest: baseExecutionRequest
|
|
984
963
|
};
|
|
985
|
-
const
|
|
986
|
-
let execReqLogger = transportContext?.logger;
|
|
987
|
-
if (execReqLogger) {
|
|
988
|
-
if (requestId) {
|
|
989
|
-
execReqLogger = execReqLogger.child({ requestId });
|
|
990
|
-
}
|
|
991
|
-
loggerForExecutionRequest.set(baseExecutionRequest, execReqLogger);
|
|
992
|
-
}
|
|
993
|
-
execReqLogger = execReqLogger?.child?.({ subgraph: subgraphName });
|
|
964
|
+
const log = transportContext.log.child({ subgraph: subgraphName });
|
|
994
965
|
if (onSubgraphExecuteHooks.length === 0) {
|
|
995
966
|
return baseExecutor(baseExecutionRequest);
|
|
996
967
|
}
|
|
@@ -1014,11 +985,10 @@ function wrapExecutorWithHooks({
|
|
|
1014
985
|
},
|
|
1015
986
|
executor,
|
|
1016
987
|
setExecutor(newExecutor) {
|
|
1017
|
-
|
|
988
|
+
log?.debug("executor has been updated");
|
|
1018
989
|
executor = newExecutor;
|
|
1019
990
|
},
|
|
1020
|
-
|
|
1021
|
-
logger: execReqLogger
|
|
991
|
+
log
|
|
1022
992
|
}),
|
|
1023
993
|
onSubgraphExecuteDoneHooks
|
|
1024
994
|
),
|
|
@@ -1036,10 +1006,7 @@ function wrapExecutorWithHooks({
|
|
|
1036
1006
|
(onSubgraphExecuteDoneHook) => onSubgraphExecuteDoneHook({
|
|
1037
1007
|
result: currentResult,
|
|
1038
1008
|
setResult(newResult) {
|
|
1039
|
-
|
|
1040
|
-
"overriding result with: ",
|
|
1041
|
-
newResult
|
|
1042
|
-
);
|
|
1009
|
+
log?.debug("overriding result with: ", newResult);
|
|
1043
1010
|
currentResult = newResult;
|
|
1044
1011
|
}
|
|
1045
1012
|
}),
|
|
@@ -1073,10 +1040,7 @@ function wrapExecutorWithHooks({
|
|
|
1073
1040
|
(onNext) => onNext({
|
|
1074
1041
|
result: currentResult2,
|
|
1075
1042
|
setResult: (res) => {
|
|
1076
|
-
|
|
1077
|
-
"overriding result with: ",
|
|
1078
|
-
res
|
|
1079
|
-
);
|
|
1043
|
+
log?.debug("overriding result with: ", res);
|
|
1080
1044
|
currentResult2 = res;
|
|
1081
1045
|
}
|
|
1082
1046
|
})
|
|
@@ -1092,6 +1056,13 @@ function wrapExecutorWithHooks({
|
|
|
1092
1056
|
);
|
|
1093
1057
|
}
|
|
1094
1058
|
);
|
|
1059
|
+
}
|
|
1060
|
+
return function instrumentedExecutor(executionRequest) {
|
|
1061
|
+
const subgraphInstrument = instrumentation()?.subgraphExecute;
|
|
1062
|
+
return getInstrumented({ executionRequest, subgraphName }).asyncFn(
|
|
1063
|
+
subgraphInstrument,
|
|
1064
|
+
executorWithHooks
|
|
1065
|
+
)(executionRequest);
|
|
1095
1066
|
};
|
|
1096
1067
|
}
|
|
1097
1068
|
function compareSchemas(a, b) {
|
|
@@ -1119,18 +1090,10 @@ function compareSchemas(a, b) {
|
|
|
1119
1090
|
function compareSubgraphNames(name1, name2) {
|
|
1120
1091
|
return constantCase(name1) === constantCase(name2);
|
|
1121
1092
|
}
|
|
1122
|
-
function wrapMergedTypeResolver(originalResolver, typeName, onDelegationStageExecuteHooks,
|
|
1093
|
+
function wrapMergedTypeResolver(originalResolver, typeName, onDelegationStageExecuteHooks, log) {
|
|
1123
1094
|
return (object, context, info, subschema, selectionSet, key, type) => {
|
|
1124
|
-
let logger = baseLogger;
|
|
1125
|
-
let requestId;
|
|
1126
|
-
if (logger && context["request"]) {
|
|
1127
|
-
requestId = requestIdByRequest.get(context["request"]);
|
|
1128
|
-
if (requestId) {
|
|
1129
|
-
logger = logger.child({ requestId });
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
1095
|
if (subschema.name) {
|
|
1133
|
-
|
|
1096
|
+
log = log.child({ subgraph: subschema.name });
|
|
1134
1097
|
}
|
|
1135
1098
|
let resolver = originalResolver;
|
|
1136
1099
|
function setResolver(newResolver) {
|
|
@@ -1148,8 +1111,7 @@ function wrapMergedTypeResolver(originalResolver, typeName, onDelegationStageExe
|
|
|
1148
1111
|
key,
|
|
1149
1112
|
typeName,
|
|
1150
1113
|
type,
|
|
1151
|
-
|
|
1152
|
-
logger,
|
|
1114
|
+
log,
|
|
1153
1115
|
resolver,
|
|
1154
1116
|
setResolver
|
|
1155
1117
|
});
|
|
@@ -1288,7 +1250,7 @@ class UnifiedGraphManager {
|
|
|
1288
1250
|
this.onDelegationPlanHooks = opts?.onDelegationPlanHooks || [];
|
|
1289
1251
|
this.onDelegationStageExecuteHooks = opts?.onDelegationStageExecuteHooks || [];
|
|
1290
1252
|
if (opts.pollingInterval != null) {
|
|
1291
|
-
opts.transportContext
|
|
1253
|
+
opts.transportContext.log.debug(
|
|
1292
1254
|
`Starting polling to Supergraph with interval ${millisecondsToStr(opts.pollingInterval)}`
|
|
1293
1255
|
);
|
|
1294
1256
|
}
|
|
@@ -1310,16 +1272,16 @@ class UnifiedGraphManager {
|
|
|
1310
1272
|
instrumentation;
|
|
1311
1273
|
ensureUnifiedGraph() {
|
|
1312
1274
|
if (this.polling$ == null && this.opts?.pollingInterval != null && this.lastLoadTime != null && Date.now() - this.lastLoadTime >= this.opts.pollingInterval) {
|
|
1313
|
-
this.opts?.transportContext
|
|
1275
|
+
this.opts?.transportContext.log.debug(`Polling Supergraph`);
|
|
1314
1276
|
this.polling$ = handleMaybePromise(
|
|
1315
1277
|
() => this.getAndSetUnifiedGraph(),
|
|
1316
1278
|
() => {
|
|
1317
1279
|
this.polling$ = void 0;
|
|
1318
1280
|
},
|
|
1319
1281
|
(err) => {
|
|
1320
|
-
this.opts.transportContext
|
|
1321
|
-
|
|
1322
|
-
|
|
1282
|
+
this.opts.transportContext.log.error(
|
|
1283
|
+
err,
|
|
1284
|
+
"Failed to poll Supergraph"
|
|
1323
1285
|
);
|
|
1324
1286
|
this.polling$ = void 0;
|
|
1325
1287
|
}
|
|
@@ -1327,18 +1289,20 @@ class UnifiedGraphManager {
|
|
|
1327
1289
|
}
|
|
1328
1290
|
if (!this.unifiedGraph) {
|
|
1329
1291
|
if (!this.initialUnifiedGraph$) {
|
|
1330
|
-
this.opts?.transportContext
|
|
1292
|
+
this.opts?.transportContext.log.debug(
|
|
1331
1293
|
"Fetching the initial Supergraph"
|
|
1332
1294
|
);
|
|
1333
|
-
if (this.opts.transportContext
|
|
1334
|
-
this.opts.transportContext
|
|
1335
|
-
|
|
1295
|
+
if (this.opts.transportContext.cache) {
|
|
1296
|
+
this.opts.transportContext.log.debug(
|
|
1297
|
+
{ key: UNIFIEDGRAPH_CACHE_KEY },
|
|
1298
|
+
"Searching for Supergraph in cache..."
|
|
1336
1299
|
);
|
|
1337
1300
|
this.initialUnifiedGraph$ = handleMaybePromise(
|
|
1338
|
-
() => this.opts.transportContext
|
|
1301
|
+
() => this.opts.transportContext.cache?.get(UNIFIEDGRAPH_CACHE_KEY),
|
|
1339
1302
|
(cachedUnifiedGraph) => {
|
|
1340
1303
|
if (cachedUnifiedGraph) {
|
|
1341
|
-
this.opts.transportContext
|
|
1304
|
+
this.opts.transportContext.log.debug(
|
|
1305
|
+
{ key: UNIFIEDGRAPH_CACHE_KEY },
|
|
1342
1306
|
"Found Supergraph in cache"
|
|
1343
1307
|
);
|
|
1344
1308
|
return this.handleLoadedUnifiedGraph(cachedUnifiedGraph, true);
|
|
@@ -1356,7 +1320,8 @@ class UnifiedGraphManager {
|
|
|
1356
1320
|
() => this.initialUnifiedGraph$,
|
|
1357
1321
|
(v) => {
|
|
1358
1322
|
this.initialUnifiedGraph$ = void 0;
|
|
1359
|
-
this.opts.transportContext
|
|
1323
|
+
this.opts.transportContext.log.debug(
|
|
1324
|
+
{ key: UNIFIEDGRAPH_CACHE_KEY },
|
|
1360
1325
|
"Initial Supergraph fetched"
|
|
1361
1326
|
);
|
|
1362
1327
|
return v;
|
|
@@ -1371,7 +1336,7 @@ class UnifiedGraphManager {
|
|
|
1371
1336
|
handleLoadedUnifiedGraph(loadedUnifiedGraph, doNotCache) {
|
|
1372
1337
|
if (loadedUnifiedGraph != null) {
|
|
1373
1338
|
if (this.lastLoadedUnifiedGraph != null && compareSchemas(loadedUnifiedGraph, this.lastLoadedUnifiedGraph)) {
|
|
1374
|
-
this.opts.transportContext
|
|
1339
|
+
this.opts.transportContext.log.debug(
|
|
1375
1340
|
"Supergraph has not been changed, skipping..."
|
|
1376
1341
|
);
|
|
1377
1342
|
this.lastLoadTime = Date.now();
|
|
@@ -1397,13 +1362,14 @@ class UnifiedGraphManager {
|
|
|
1397
1362
|
// NOTE: we default to 60s because Cloudflare KV TTL does not accept anything less
|
|
1398
1363
|
60
|
|
1399
1364
|
);
|
|
1400
|
-
this.opts.transportContext.
|
|
1401
|
-
|
|
1365
|
+
this.opts.transportContext.log.debug(
|
|
1366
|
+
{ ttl, key: UNIFIEDGRAPH_CACHE_KEY },
|
|
1367
|
+
"Caching Supergraph"
|
|
1402
1368
|
);
|
|
1403
|
-
const logCacheSetError = (
|
|
1404
|
-
this.opts.transportContext
|
|
1405
|
-
|
|
1406
|
-
|
|
1369
|
+
const logCacheSetError = (err) => {
|
|
1370
|
+
this.opts.transportContext.log.debug(
|
|
1371
|
+
{ err, ttl, key: UNIFIEDGRAPH_CACHE_KEY },
|
|
1372
|
+
"Unable to cache Supergraph"
|
|
1407
1373
|
);
|
|
1408
1374
|
};
|
|
1409
1375
|
try {
|
|
@@ -1420,10 +1386,10 @@ class UnifiedGraphManager {
|
|
|
1420
1386
|
} catch (e) {
|
|
1421
1387
|
logCacheSetError(e);
|
|
1422
1388
|
}
|
|
1423
|
-
} catch (
|
|
1424
|
-
this.opts.transportContext.
|
|
1425
|
-
|
|
1426
|
-
|
|
1389
|
+
} catch (err) {
|
|
1390
|
+
this.opts.transportContext.log.error(
|
|
1391
|
+
err,
|
|
1392
|
+
"Failed to initiate caching of Supergraph"
|
|
1427
1393
|
);
|
|
1428
1394
|
}
|
|
1429
1395
|
}
|
|
@@ -1448,7 +1414,7 @@ class UnifiedGraphManager {
|
|
|
1448
1414
|
onDelegationPlanHooks: this.onDelegationPlanHooks,
|
|
1449
1415
|
onDelegationStageExecuteHooks: this.onDelegationStageExecuteHooks,
|
|
1450
1416
|
onDelegateHooks: this.opts.onDelegateHooks,
|
|
1451
|
-
|
|
1417
|
+
log: this.opts.transportContext.log
|
|
1452
1418
|
});
|
|
1453
1419
|
const transportExecutorStack = new AsyncDisposableStack();
|
|
1454
1420
|
const onSubgraphExecute = getOnSubgraphExecute({
|
|
@@ -1487,7 +1453,7 @@ class UnifiedGraphManager {
|
|
|
1487
1453
|
}
|
|
1488
1454
|
}
|
|
1489
1455
|
);
|
|
1490
|
-
this.opts.transportContext
|
|
1456
|
+
this.opts.transportContext.log.debug(
|
|
1491
1457
|
"Supergraph has been changed, updating..."
|
|
1492
1458
|
);
|
|
1493
1459
|
}
|
|
@@ -1499,9 +1465,9 @@ class UnifiedGraphManager {
|
|
|
1499
1465
|
},
|
|
1500
1466
|
(err) => {
|
|
1501
1467
|
this.disposeReason = void 0;
|
|
1502
|
-
this.opts.transportContext
|
|
1503
|
-
|
|
1504
|
-
|
|
1468
|
+
this.opts.transportContext.log.error(
|
|
1469
|
+
err,
|
|
1470
|
+
"Failed to dispose the existing transports and executors"
|
|
1505
1471
|
);
|
|
1506
1472
|
return this.unifiedGraph;
|
|
1507
1473
|
}
|
|
@@ -1521,10 +1487,7 @@ class UnifiedGraphManager {
|
|
|
1521
1487
|
() => this.opts.getUnifiedGraph(this.opts.transportContext || {}),
|
|
1522
1488
|
(loadedUnifiedGraph) => this.handleLoadedUnifiedGraph(loadedUnifiedGraph),
|
|
1523
1489
|
(err) => {
|
|
1524
|
-
this.opts.transportContext
|
|
1525
|
-
"Failed to load Supergraph",
|
|
1526
|
-
err
|
|
1527
|
-
);
|
|
1490
|
+
this.opts.transportContext.log.error(err, "Failed to load Supergraph");
|
|
1528
1491
|
this.lastLoadTime = Date.now();
|
|
1529
1492
|
this.disposeReason = void 0;
|
|
1530
1493
|
this.polling$ = void 0;
|
|
@@ -1625,7 +1588,7 @@ function getExecutorForUnifiedGraph(opts) {
|
|
|
1625
1588
|
() => unifiedGraphManager.getContext(execReq.context),
|
|
1626
1589
|
(context) => {
|
|
1627
1590
|
function handleExecutor(executor) {
|
|
1628
|
-
opts?.transportContext
|
|
1591
|
+
opts?.transportContext.log.debug(
|
|
1629
1592
|
"Executing request on unified graph",
|
|
1630
1593
|
() => print(execReq.document)
|
|
1631
1594
|
);
|
|
@@ -1641,7 +1604,7 @@ function getExecutorForUnifiedGraph(opts) {
|
|
|
1641
1604
|
return handleMaybePromise(
|
|
1642
1605
|
() => unifiedGraphManager.getUnifiedGraph(),
|
|
1643
1606
|
(unifiedGraph) => {
|
|
1644
|
-
opts?.transportContext
|
|
1607
|
+
opts?.transportContext.log.debug(
|
|
1645
1608
|
"Executing request on unified graph",
|
|
1646
1609
|
() => print(execReq.document)
|
|
1647
1610
|
);
|
|
@@ -1661,9 +1624,7 @@ function getExecutorForUnifiedGraph(opts) {
|
|
|
1661
1624
|
enumerable: true,
|
|
1662
1625
|
get() {
|
|
1663
1626
|
return function unifiedGraphExecutorDispose() {
|
|
1664
|
-
opts?.transportContext
|
|
1665
|
-
"Disposing unified graph executor"
|
|
1666
|
-
);
|
|
1627
|
+
opts?.transportContext.log.debug("Disposing unified graph executor");
|
|
1667
1628
|
return unifiedGraphManager[DisposableSymbols.asyncDispose]();
|
|
1668
1629
|
};
|
|
1669
1630
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/fusion-runtime",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.13-alpha-cd2e85546d0c2bef716fc44935bc37a496a3ba57",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Runtime for GraphQL Mesh Fusion Supergraph",
|
|
6
6
|
"repository": {
|
|
@@ -45,8 +45,9 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@envelop/core": "^5.2.3",
|
|
47
47
|
"@envelop/instrumentation": "^1.0.0",
|
|
48
|
+
"@graphql-hive/logger": "1.0.0-alpha-cd2e85546d0c2bef716fc44935bc37a496a3ba57",
|
|
48
49
|
"@graphql-mesh/cross-helpers": "^0.4.10",
|
|
49
|
-
"@graphql-mesh/transport-common": "
|
|
50
|
+
"@graphql-mesh/transport-common": "0.7.35-alpha-cd2e85546d0c2bef716fc44935bc37a496a3ba57",
|
|
50
51
|
"@graphql-mesh/types": "^0.104.0",
|
|
51
52
|
"@graphql-mesh/utils": "^0.104.2",
|
|
52
53
|
"@graphql-tools/batch-execute": "^9.0.15",
|