@graphql-tools/federation 3.1.7 → 3.1.8-rc-2f72fd40bed22a2864173f14d4cdcedacc503a73

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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # @graphql-tools/federation
2
2
 
3
+ ## 3.1.8-rc-2f72fd40bed22a2864173f14d4cdcedacc503a73
4
+
5
+ ### Patch Changes
6
+
7
+ - [#950](https://github.com/graphql-hive/gateway/pull/950) [`c7ea2c5`](https://github.com/graphql-hive/gateway/commit/c7ea2c5ae71b6b338ef22edd927a3fc93803965f) Thanks [@kroupacz](https://github.com/kroupacz)! - Errors should not be swallowed when it is thrown from the shared root
8
+
9
+ - Updated dependencies [[`c7ea2c5`](https://github.com/graphql-hive/gateway/commit/c7ea2c5ae71b6b338ef22edd927a3fc93803965f)]:
10
+ - @graphql-tools/delegate@10.2.17-rc-2f72fd40bed22a2864173f14d4cdcedacc503a73
11
+ - @graphql-tools/stitch@9.4.22-rc-2f72fd40bed22a2864173f14d4cdcedacc503a73
12
+ - @graphql-tools/wrap@10.0.35-rc-2f72fd40bed22a2864173f14d4cdcedacc503a73
13
+
3
14
  ## 3.1.7
4
15
 
5
16
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -980,6 +980,7 @@ function getStitchingOptionsFromSupergraphSdl(opts) {
980
980
  }
981
981
  let executor = executorHttp.buildHTTPExecutor({
982
982
  endpoint,
983
+ serviceName: subgraphName,
983
984
  ...httpExecutorOpts
984
985
  });
985
986
  if (globalThis.process?.env?.["DEBUG"]) {
@@ -1197,6 +1198,25 @@ function getStitchingOptionsFromSupergraphSdl(opts) {
1197
1198
  }
1198
1199
  const jobs = [];
1199
1200
  let hasPromise = false;
1201
+ const fieldNames = /* @__PURE__ */ new Set();
1202
+ currentAvailableSelectionSet?.selections.forEach((selection) => {
1203
+ if (selection.kind === graphql.Kind.FIELD && selection.name.value === info.fieldName) {
1204
+ selection.selectionSet?.selections.forEach((selection2) => {
1205
+ if (selection2.kind === graphql.Kind.FIELD) {
1206
+ fieldNames.add(selection2.name.value);
1207
+ }
1208
+ });
1209
+ }
1210
+ });
1211
+ currentUnavailableSelectionSet?.selections.forEach((selection) => {
1212
+ if (selection.kind === graphql.Kind.FIELD && selection.name.value === info.fieldName) {
1213
+ selection.selectionSet?.selections.forEach((selection2) => {
1214
+ if (selection2.kind === graphql.Kind.FIELD) {
1215
+ fieldNames.add(selection2.name.value);
1216
+ }
1217
+ });
1218
+ }
1219
+ });
1200
1220
  const mainJob = delegate.delegateToSchema({
1201
1221
  schema: currentSubschema,
1202
1222
  operation: rootTypeMap.get(info.parentType.name) || "query",
@@ -1241,9 +1261,11 @@ function getStitchingOptionsFromSupergraphSdl(opts) {
1241
1261
  return jobs[0];
1242
1262
  }
1243
1263
  if (hasPromise) {
1244
- return Promise.all(jobs).then((results) => mergeResults(results));
1264
+ return Promise.all(jobs).then(
1265
+ (results) => mergeResults(results, fieldNames)
1266
+ );
1245
1267
  }
1246
- return mergeResults(jobs);
1268
+ return mergeResults(jobs, fieldNames);
1247
1269
  };
1248
1270
  if (operationType === "subscription") {
1249
1271
  return {
@@ -1428,13 +1450,45 @@ const specifiedTypeNames = [
1428
1450
  "_Any",
1429
1451
  "_Entity"
1430
1452
  ];
1431
- function makeExternalObject(data, errors) {
1453
+ function makeExternalObject(data, errors, fieldNames) {
1432
1454
  if (!delegate.isExternalObject(data) && typeof data === "object" && data != null) {
1433
1455
  data[delegate.UNPATHED_ERRORS_SYMBOL] = errors;
1434
1456
  }
1457
+ if (errors.length) {
1458
+ const errorsToPop = [...errors];
1459
+ const fieldNamesToPop = [];
1460
+ for (const fieldName of fieldNames) {
1461
+ if (data?.[fieldName] == null) {
1462
+ fieldNamesToPop.push(fieldName);
1463
+ }
1464
+ }
1465
+ while (fieldNamesToPop.length && errorsToPop.length) {
1466
+ const fieldName = fieldNamesToPop.pop();
1467
+ if (!fieldName) {
1468
+ break;
1469
+ }
1470
+ const error = errorsToPop.pop();
1471
+ if (!error) {
1472
+ break;
1473
+ }
1474
+ let errorToSet;
1475
+ if (fieldNamesToPop.length || !errorsToPop.length) {
1476
+ errorToSet = error;
1477
+ } else {
1478
+ errorToSet = new AggregateError(
1479
+ errorsToPop,
1480
+ errorsToPop.map((error2) => error2.message).join(", \n")
1481
+ );
1482
+ }
1483
+ if (errorToSet) {
1484
+ data ||= {};
1485
+ data[fieldName] = errorToSet;
1486
+ }
1487
+ }
1488
+ }
1435
1489
  return data;
1436
1490
  }
1437
- function mergeResults(results) {
1491
+ function mergeResults(results, fieldNames) {
1438
1492
  const errors = [];
1439
1493
  const datas = [];
1440
1494
  for (const result of results) {
@@ -1448,9 +1502,13 @@ function mergeResults(results) {
1448
1502
  }
1449
1503
  if (datas.length) {
1450
1504
  if (datas.length === 1) {
1451
- return makeExternalObject(datas[0], errors);
1505
+ return makeExternalObject(datas[0], errors, fieldNames);
1452
1506
  }
1453
- return makeExternalObject(utils.mergeDeep(datas, void 0, true, true), errors);
1507
+ return makeExternalObject(
1508
+ utils.mergeDeep(datas, void 0, true, true),
1509
+ errors,
1510
+ fieldNames
1511
+ );
1454
1512
  }
1455
1513
  if (errors.length) {
1456
1514
  if (errors.length === 1) {
package/dist/index.js CHANGED
@@ -978,6 +978,7 @@ function getStitchingOptionsFromSupergraphSdl(opts) {
978
978
  }
979
979
  let executor = buildHTTPExecutor({
980
980
  endpoint,
981
+ serviceName: subgraphName,
981
982
  ...httpExecutorOpts
982
983
  });
983
984
  if (globalThis.process?.env?.["DEBUG"]) {
@@ -1195,6 +1196,25 @@ function getStitchingOptionsFromSupergraphSdl(opts) {
1195
1196
  }
1196
1197
  const jobs = [];
1197
1198
  let hasPromise = false;
1199
+ const fieldNames = /* @__PURE__ */ new Set();
1200
+ currentAvailableSelectionSet?.selections.forEach((selection) => {
1201
+ if (selection.kind === Kind.FIELD && selection.name.value === info.fieldName) {
1202
+ selection.selectionSet?.selections.forEach((selection2) => {
1203
+ if (selection2.kind === Kind.FIELD) {
1204
+ fieldNames.add(selection2.name.value);
1205
+ }
1206
+ });
1207
+ }
1208
+ });
1209
+ currentUnavailableSelectionSet?.selections.forEach((selection) => {
1210
+ if (selection.kind === Kind.FIELD && selection.name.value === info.fieldName) {
1211
+ selection.selectionSet?.selections.forEach((selection2) => {
1212
+ if (selection2.kind === Kind.FIELD) {
1213
+ fieldNames.add(selection2.name.value);
1214
+ }
1215
+ });
1216
+ }
1217
+ });
1198
1218
  const mainJob = delegateToSchema({
1199
1219
  schema: currentSubschema,
1200
1220
  operation: rootTypeMap.get(info.parentType.name) || "query",
@@ -1239,9 +1259,11 @@ function getStitchingOptionsFromSupergraphSdl(opts) {
1239
1259
  return jobs[0];
1240
1260
  }
1241
1261
  if (hasPromise) {
1242
- return Promise.all(jobs).then((results) => mergeResults(results));
1262
+ return Promise.all(jobs).then(
1263
+ (results) => mergeResults(results, fieldNames)
1264
+ );
1243
1265
  }
1244
- return mergeResults(jobs);
1266
+ return mergeResults(jobs, fieldNames);
1245
1267
  };
1246
1268
  if (operationType === "subscription") {
1247
1269
  return {
@@ -1426,13 +1448,45 @@ const specifiedTypeNames = [
1426
1448
  "_Any",
1427
1449
  "_Entity"
1428
1450
  ];
1429
- function makeExternalObject(data, errors) {
1451
+ function makeExternalObject(data, errors, fieldNames) {
1430
1452
  if (!isExternalObject(data) && typeof data === "object" && data != null) {
1431
1453
  data[UNPATHED_ERRORS_SYMBOL] = errors;
1432
1454
  }
1455
+ if (errors.length) {
1456
+ const errorsToPop = [...errors];
1457
+ const fieldNamesToPop = [];
1458
+ for (const fieldName of fieldNames) {
1459
+ if (data?.[fieldName] == null) {
1460
+ fieldNamesToPop.push(fieldName);
1461
+ }
1462
+ }
1463
+ while (fieldNamesToPop.length && errorsToPop.length) {
1464
+ const fieldName = fieldNamesToPop.pop();
1465
+ if (!fieldName) {
1466
+ break;
1467
+ }
1468
+ const error = errorsToPop.pop();
1469
+ if (!error) {
1470
+ break;
1471
+ }
1472
+ let errorToSet;
1473
+ if (fieldNamesToPop.length || !errorsToPop.length) {
1474
+ errorToSet = error;
1475
+ } else {
1476
+ errorToSet = new AggregateError(
1477
+ errorsToPop,
1478
+ errorsToPop.map((error2) => error2.message).join(", \n")
1479
+ );
1480
+ }
1481
+ if (errorToSet) {
1482
+ data ||= {};
1483
+ data[fieldName] = errorToSet;
1484
+ }
1485
+ }
1486
+ }
1433
1487
  return data;
1434
1488
  }
1435
- function mergeResults(results) {
1489
+ function mergeResults(results, fieldNames) {
1436
1490
  const errors = [];
1437
1491
  const datas = [];
1438
1492
  for (const result of results) {
@@ -1446,9 +1500,13 @@ function mergeResults(results) {
1446
1500
  }
1447
1501
  if (datas.length) {
1448
1502
  if (datas.length === 1) {
1449
- return makeExternalObject(datas[0], errors);
1503
+ return makeExternalObject(datas[0], errors, fieldNames);
1450
1504
  }
1451
- return makeExternalObject(mergeDeep(datas, void 0, true, true), errors);
1505
+ return makeExternalObject(
1506
+ mergeDeep(datas, void 0, true, true),
1507
+ errors,
1508
+ fieldNames
1509
+ );
1452
1510
  }
1453
1511
  if (errors.length) {
1454
1512
  if (errors.length === 1) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/federation",
3
- "version": "3.1.7",
3
+ "version": "3.1.8-rc-2f72fd40bed22a2864173f14d4cdcedacc503a73",
4
4
  "type": "module",
5
5
  "description": "Useful tools to create and manipulate GraphQL schemas.",
6
6
  "repository": {
@@ -38,13 +38,13 @@
38
38
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
39
39
  },
40
40
  "dependencies": {
41
- "@graphql-tools/delegate": "^10.2.16",
41
+ "@graphql-tools/delegate": "10.2.17-rc-2f72fd40bed22a2864173f14d4cdcedacc503a73",
42
42
  "@graphql-tools/executor-http": "^1.3.2",
43
43
  "@graphql-tools/merge": "^9.0.12",
44
44
  "@graphql-tools/schema": "^10.0.11",
45
- "@graphql-tools/stitch": "^9.4.21",
45
+ "@graphql-tools/stitch": "9.4.22-rc-2f72fd40bed22a2864173f14d4cdcedacc503a73",
46
46
  "@graphql-tools/utils": "^10.8.1",
47
- "@graphql-tools/wrap": "^10.0.34",
47
+ "@graphql-tools/wrap": "10.0.35-rc-2f72fd40bed22a2864173f14d4cdcedacc503a73",
48
48
  "@graphql-yoga/typed-event-target": "^3.0.1",
49
49
  "@whatwg-node/disposablestack": "^0.0.6",
50
50
  "@whatwg-node/events": "^0.1.2",