@graphql-tools/delegate 10.2.9 → 10.2.10-alpha-e8878e64f4cd1ea558f9ae1848b2e315883294cd

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,81 @@
1
1
  # @graphql-tools/delegate
2
2
 
3
+ ## 10.2.10-alpha-e8878e64f4cd1ea558f9ae1848b2e315883294cd
4
+
5
+ ### Patch Changes
6
+
7
+ - [#471](https://github.com/graphql-hive/gateway/pull/471) [`e8878e6`](https://github.com/graphql-hive/gateway/commit/e8878e64f4cd1ea558f9ae1848b2e315883294cd) Thanks [@ardatan](https://github.com/ardatan)! - While creating a delegation request for the subschema, an selection set should be spreaded on the union type field correctly.
8
+
9
+ In case of the following schema;
10
+
11
+ ```graphql
12
+ type Query {
13
+ foo: Foo
14
+ }
15
+
16
+ union Foo = Bar | Baz
17
+
18
+ type Bar {
19
+ id: ID!
20
+ name: String
21
+ age: Age
22
+ }
23
+
24
+ type Age {
25
+ years: Int
26
+ months: Int
27
+ }
28
+
29
+ type Baz {
30
+ id: ID!
31
+ name: Name
32
+ age: Int
33
+ }
34
+
35
+ type Name {
36
+ first: String
37
+ last: String
38
+ }
39
+ ```
40
+
41
+ If the operation is generated as following;
42
+
43
+ ```graphql
44
+ query {
45
+ foo {
46
+ id
47
+ name
48
+ age {
49
+ years
50
+ months
51
+ }
52
+ }
53
+ }
54
+ ```
55
+
56
+ It should be spreaded on the union type field correctly as following;
57
+
58
+ ```graphql
59
+ query {
60
+ foo {
61
+ ... on Bar {
62
+ id
63
+ age {
64
+ years
65
+ months
66
+ }
67
+ }
68
+ ... on Baz {
69
+ id
70
+ name {
71
+ first
72
+ last
73
+ }
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
3
79
  ## 10.2.9
4
80
 
5
81
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -63,7 +63,7 @@ function getPlanLeftOverFromParent(parent) {
63
63
  if (parent != null && typeof parent === "object") {
64
64
  return parent[PLAN_LEFT_OVER];
65
65
  }
66
- return void 0;
66
+ return undefined;
67
67
  }
68
68
 
69
69
  const UNPATHED_ERRORS_SYMBOL = Symbol.for("subschemaErrors");
@@ -71,7 +71,7 @@ const OBJECT_SUBSCHEMA_SYMBOL = Symbol.for("initialSubschema");
71
71
  const FIELD_SUBSCHEMA_MAP_SYMBOL = Symbol.for("subschemaMap");
72
72
 
73
73
  function isExternalObject(data) {
74
- return data[UNPATHED_ERRORS_SYMBOL] !== void 0;
74
+ return data[UNPATHED_ERRORS_SYMBOL] !== undefined;
75
75
  }
76
76
  function annotateExternalObject(object, errors, subschema, subschemaMap) {
77
77
  Object.defineProperties(object, {
@@ -118,7 +118,7 @@ function mergeFields(mergedTypeInfo, object, sourceSubschema, context, info) {
118
118
  info
119
119
  )
120
120
  ),
121
- void 0
121
+ undefined
122
122
  ),
123
123
  () => object
124
124
  );
@@ -181,7 +181,7 @@ function handleResolverResult(resolverResult, subschema, selectionSet, object, c
181
181
  object[responseKey] = existingPropValue.map(
182
182
  (existingElement, index) => sourcePropValue instanceof Error ? existingElement : utils.mergeDeep(
183
183
  [existingElement, sourcePropValue[index]],
184
- void 0,
184
+ undefined,
185
185
  true,
186
186
  true
187
187
  )
@@ -189,7 +189,7 @@ function handleResolverResult(resolverResult, subschema, selectionSet, object, c
189
189
  } else if (!(sourcePropValue instanceof Error)) {
190
190
  object[responseKey] = utils.mergeDeep(
191
191
  [existingPropValue, sourcePropValue],
192
- void 0,
192
+ undefined,
193
193
  true,
194
194
  true
195
195
  );
@@ -407,7 +407,7 @@ function reportUnpathedErrorsViaNull(unpathedErrors) {
407
407
  if (unreportedErrors.length === 1 && unreportedError) {
408
408
  return graphql.locatedError(
409
409
  unreportedError,
410
- void 0,
410
+ undefined,
411
411
  unreportedError.path
412
412
  );
413
413
  }
@@ -418,7 +418,7 @@ function reportUnpathedErrorsViaNull(unpathedErrors) {
418
418
  // locatedError path argument must be defined, but it is just forwarded to a constructor that allows a undefined value
419
419
  // https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/locatedError.js#L25
420
420
  // https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/GraphQLError.js#L19
421
- graphql.locatedError(e, void 0, unreportedError?.path)
421
+ graphql.locatedError(e, undefined, unreportedError?.path)
422
422
  )
423
423
  ),
424
424
  unreportedErrors.map((error) => error.message).join(", \n")
@@ -448,9 +448,9 @@ function checkResultAndHandleErrors(result = {
448
448
  onLocatedError
449
449
  } = delegationContext;
450
450
  const { data, unpathedErrors } = mergeDataAndErrors(
451
- result.data == null ? void 0 : result.data[responseKey],
451
+ result.data == null ? undefined : result.data[responseKey],
452
452
  result.errors == null ? [] : result.errors,
453
- info != null && info.path ? graphql.responsePathAsArray(info.path) : void 0,
453
+ info != null && info.path ? graphql.responsePathAsArray(info.path) : undefined,
454
454
  onLocatedError
455
455
  );
456
456
  return resolveExternalValue(
@@ -470,7 +470,7 @@ function mergeDataAndErrors(data, errors, path, onLocatedError, index = 1) {
470
470
  }
471
471
  if (errors.length === 1 && errors[0]) {
472
472
  const error = onLocatedError ? onLocatedError(errors[0]) : errors[0];
473
- const newPath = path === void 0 ? error.path : !error.path ? path : path.concat(error.path.slice(1));
473
+ const newPath = path === undefined ? error.path : !error.path ? path : path.concat(error.path.slice(1));
474
474
  return { data: utils.relocatedError(errors[0], newPath), unpathedErrors: [] };
475
475
  }
476
476
  const combinedError = new AggregateError(
@@ -480,7 +480,7 @@ function mergeDataAndErrors(data, errors, path, onLocatedError, index = 1) {
480
480
  // locatedError path argument must be defined, but it is just forwarded to a constructor that allows a undefined value
481
481
  // https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/locatedError.js#L25
482
482
  // https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/GraphQLError.js#L19
483
- graphql.locatedError(e, void 0, path)
483
+ graphql.locatedError(e, undefined, path)
484
484
  )
485
485
  ),
486
486
  errors.map((error) => error.message).join(", \n")
@@ -496,7 +496,7 @@ function mergeDataAndErrors(data, errors, path, onLocatedError, index = 1) {
496
496
  const pathSegment = error.path?.[index];
497
497
  if (pathSegment != null) {
498
498
  let pathSegmentErrors = errorMap.get(pathSegment);
499
- if (pathSegmentErrors === void 0) {
499
+ if (pathSegmentErrors === undefined) {
500
500
  pathSegmentErrors = [error];
501
501
  errorMap.set(pathSegment, pathSegmentErrors);
502
502
  } else {
@@ -507,7 +507,7 @@ function mergeDataAndErrors(data, errors, path, onLocatedError, index = 1) {
507
507
  }
508
508
  }
509
509
  for (const [pathSegment, pathSegmentErrors] of errorMap) {
510
- if (data[pathSegment] !== void 0) {
510
+ if (data[pathSegment] !== undefined) {
511
511
  const { data: newData, unpathedErrors: newErrors } = mergeDataAndErrors(
512
512
  data[pathSegment],
513
513
  pathSegmentErrors,
@@ -562,7 +562,7 @@ const getTypeInfo = utils.memoize1(function getTypeInfo2(schema) {
562
562
  return new graphql.TypeInfo(schema);
563
563
  });
564
564
  const getTypeInfoWithType = utils.memoize2(function getTypeInfoWithType2(schema, type) {
565
- return graphql.versionInfo.major < 16 ? new graphql.TypeInfo(schema, void 0, type) : new graphql.TypeInfo(schema, type);
565
+ return graphql.versionInfo.major < 16 ? new graphql.TypeInfo(schema, undefined, type) : new graphql.TypeInfo(schema, type);
566
566
  });
567
567
 
568
568
  function finalizeGatewayDocument(targetSchema, fragments, operations, onOverlappingAliases, delegationContext) {
@@ -718,7 +718,7 @@ function finalizeGatewayRequest(originalRequest, delegationContext, onOverlappin
718
718
  if (variables != null) {
719
719
  for (const variableName of usedVariables) {
720
720
  const variableValue = variables[variableName];
721
- if (variableValue !== void 0) {
721
+ if (variableValue !== undefined) {
722
722
  newVariables[variableName] = variableValue;
723
723
  }
724
724
  }
@@ -929,9 +929,18 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
929
929
  }
930
930
  if (graphql.isUnionType(parentType) && typeInfo.getType() == null) {
931
931
  const possibleTypeNames = [];
932
+ const fieldName = node.name.value;
932
933
  for (const memberType of parentType.getTypes()) {
933
- const possibleField = memberType.getFields()[node.name.value];
934
+ const memberFields = memberType.getFields();
935
+ const possibleField = memberFields[fieldName];
934
936
  if (possibleField != null) {
937
+ const namedType = graphql.getNamedType(possibleField.type);
938
+ if (node.selectionSet?.selections?.length && graphql.isLeafType(namedType)) {
939
+ continue;
940
+ }
941
+ if (!node.selectionSet?.selections?.length && graphql.isCompositeType(namedType)) {
942
+ continue;
943
+ }
935
944
  possibleTypeNames.push(memberType.name);
936
945
  }
937
946
  }
@@ -952,7 +961,7 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
952
961
  }));
953
962
  }
954
963
  }
955
- return void 0;
964
+ return undefined;
956
965
  },
957
966
  leave: (node) => {
958
967
  const type2 = typeInfo.getType();
@@ -960,7 +969,7 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
960
969
  return null;
961
970
  }
962
971
  const namedType = graphql.getNamedType(type2);
963
- if (!schema.getType(namedType.name) == null) {
972
+ if (schema.getType(namedType.name) == null) {
964
973
  return null;
965
974
  }
966
975
  if (graphql.isObjectType(namedType) || graphql.isInterfaceType(namedType)) {
@@ -969,7 +978,7 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
969
978
  return null;
970
979
  }
971
980
  }
972
- return void 0;
981
+ return undefined;
973
982
  }
974
983
  },
975
984
  [graphql.Kind.FRAGMENT_SPREAD]: {
@@ -983,7 +992,7 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
983
992
  return null;
984
993
  }
985
994
  usedFragments.push(node.name.value);
986
- return void 0;
995
+ return undefined;
987
996
  }
988
997
  },
989
998
  [graphql.Kind.SELECTION_SET]: {
@@ -1019,7 +1028,7 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
1019
1028
  return null;
1020
1029
  }
1021
1030
  }
1022
- return void 0;
1031
+ return undefined;
1023
1032
  },
1024
1033
  leave: (selection, _key, parent) => {
1025
1034
  if (!selection.selectionSet?.selections?.length) {
@@ -1570,7 +1579,7 @@ function wrapConcreteTypes(returnType, targetSchema, document) {
1570
1579
  if (!rootTypeNames.has(typeName)) {
1571
1580
  return false;
1572
1581
  }
1573
- return void 0;
1582
+ return undefined;
1574
1583
  },
1575
1584
  [graphql.Kind.FIELD]: (node) => {
1576
1585
  const fieldType = typeInfo.getType();
@@ -1596,7 +1605,7 @@ function wrapConcreteTypes(returnType, targetSchema, document) {
1596
1605
  };
1597
1606
  }
1598
1607
  }
1599
- return void 0;
1608
+ return undefined;
1600
1609
  }
1601
1610
  }),
1602
1611
  // visitorKeys argument usage a la https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-graphql/src/batching/merge-queries.js
@@ -1722,7 +1731,7 @@ function createRequest({
1722
1731
  newSelectionSet = selections.length ? {
1723
1732
  kind: graphql.Kind.SELECTION_SET,
1724
1733
  selections
1725
- } : void 0;
1734
+ } : undefined;
1726
1735
  const args = fieldNodes?.[0]?.arguments;
1727
1736
  if (args) {
1728
1737
  for (const argNode of args) {
@@ -1744,7 +1753,7 @@ function createRequest({
1744
1753
  varType,
1745
1754
  variableValues?.[varName]
1746
1755
  );
1747
- if (serializedValue !== void 0) {
1756
+ if (serializedValue !== undefined) {
1748
1757
  newVariables[varName] = serializedValue;
1749
1758
  }
1750
1759
  }
@@ -1760,7 +1769,7 @@ function createRequest({
1760
1769
  }
1761
1770
  const fieldNode = fieldNodes?.[0];
1762
1771
  const rootFieldName = targetFieldName ?? fieldNode?.name.value;
1763
- if (rootFieldName === void 0) {
1772
+ if (rootFieldName === undefined) {
1764
1773
  throw new Error(
1765
1774
  `Either "targetFieldName" or a non empty "fieldNodes" array must be provided.`
1766
1775
  );
@@ -1778,7 +1787,7 @@ function createRequest({
1778
1787
  const operationName = targetOperationName ? {
1779
1788
  kind: graphql.Kind.NAME,
1780
1789
  value: targetOperationName
1781
- } : void 0;
1790
+ } : undefined;
1782
1791
  const operationDefinition = {
1783
1792
  kind: graphql.Kind.OPERATION_DEFINITION,
1784
1793
  name: operationName,
@@ -1825,9 +1834,9 @@ function updateArgumentsWithDefaults(sourceParentType, sourceFieldName, argument
1825
1834
  for (const argument of sourceField.args) {
1826
1835
  const argName = argument.name;
1827
1836
  const sourceArgType = argument.type;
1828
- if (argumentNodeMap[argName] === void 0) {
1837
+ if (argumentNodeMap[argName] === undefined) {
1829
1838
  const defaultValue = argument.defaultValue;
1830
- if (defaultValue !== void 0) {
1839
+ if (defaultValue !== undefined) {
1831
1840
  utils.updateArgument(
1832
1841
  argumentNodeMap,
1833
1842
  variableDefinitionMap,
@@ -1889,7 +1898,7 @@ function defaultMergedResolver(parent, args, context, info) {
1889
1898
  }
1890
1899
  return deferred.promise;
1891
1900
  }
1892
- return void 0;
1901
+ return undefined;
1893
1902
  }
1894
1903
  return handleResult(parent, responseKey, context, info);
1895
1904
  }
@@ -2116,8 +2125,8 @@ function parentSatisfiedSelectionSet(parent, selectionSet) {
2116
2125
  const subschemas2 = /* @__PURE__ */ new Set();
2117
2126
  for (const item of parent) {
2118
2127
  const satisfied = parentSatisfiedSelectionSet(item, selectionSet);
2119
- if (satisfied === void 0) {
2120
- return void 0;
2128
+ if (satisfied === undefined) {
2129
+ return undefined;
2121
2130
  }
2122
2131
  for (const subschema of satisfied) {
2123
2132
  subschemas2.add(subschema);
@@ -2128,15 +2137,15 @@ function parentSatisfiedSelectionSet(parent, selectionSet) {
2128
2137
  if (parent === null) {
2129
2138
  return /* @__PURE__ */ new Set();
2130
2139
  }
2131
- if (parent === void 0) {
2132
- return void 0;
2140
+ if (parent === undefined) {
2141
+ return undefined;
2133
2142
  }
2134
2143
  const subschemas = /* @__PURE__ */ new Set();
2135
2144
  for (const selection of selectionSet.selections) {
2136
2145
  if (selection.kind === graphql.Kind.FIELD) {
2137
2146
  const responseKey = selection.alias?.value ?? selection.name.value;
2138
- if (parent[responseKey] === void 0) {
2139
- return void 0;
2147
+ if (parent[responseKey] === undefined) {
2148
+ return undefined;
2140
2149
  }
2141
2150
  if (isExternalObject(parent)) {
2142
2151
  const subschema = getSubschema(parent, responseKey);
@@ -2152,8 +2161,8 @@ function parentSatisfiedSelectionSet(parent, selectionSet) {
2152
2161
  parent[responseKey],
2153
2162
  selection.selectionSet
2154
2163
  );
2155
- if (satisfied === void 0) {
2156
- return void 0;
2164
+ if (satisfied === undefined) {
2165
+ return undefined;
2157
2166
  }
2158
2167
  for (const subschema of satisfied) {
2159
2168
  subschemas.add(subschema);
@@ -2164,8 +2173,8 @@ function parentSatisfiedSelectionSet(parent, selectionSet) {
2164
2173
  parent,
2165
2174
  selection.selectionSet
2166
2175
  );
2167
- if (inlineSatisfied === void 0) {
2168
- return void 0;
2176
+ if (inlineSatisfied === undefined) {
2177
+ return undefined;
2169
2178
  }
2170
2179
  for (const subschema of inlineSatisfied) {
2171
2180
  subschemas.add(subschema);
@@ -2219,7 +2228,7 @@ function isSubschemaConfig(value) {
2219
2228
  function cloneSubschemaConfig(subschemaConfig) {
2220
2229
  const newSubschemaConfig = {
2221
2230
  ...subschemaConfig,
2222
- transforms: subschemaConfig.transforms != null ? [...subschemaConfig.transforms] : void 0
2231
+ transforms: subschemaConfig.transforms != null ? [...subschemaConfig.transforms] : undefined
2223
2232
  };
2224
2233
  if (newSubschemaConfig.merge != null) {
2225
2234
  newSubschemaConfig.merge = { ...subschemaConfig.merge };
@@ -2405,7 +2414,7 @@ function getDelegationContext({
2405
2414
  }
2406
2415
  return {
2407
2416
  subschema: schema,
2408
- subschemaConfig: void 0,
2417
+ subschemaConfig: undefined,
2409
2418
  targetSchema: subschemaOrSubschemaConfig,
2410
2419
  operation,
2411
2420
  fieldName: targetFieldName,
@@ -2631,7 +2640,7 @@ function subtractSelectionSets(selectionSetA, selectionSetB) {
2631
2640
  return null;
2632
2641
  }
2633
2642
  }
2634
- return void 0;
2643
+ return undefined;
2635
2644
  }
2636
2645
  },
2637
2646
  [graphql.Kind.SELECTION_SET]: {
@@ -2639,7 +2648,7 @@ function subtractSelectionSets(selectionSetA, selectionSetB) {
2639
2648
  if (node.selections.length === 0) {
2640
2649
  return null;
2641
2650
  }
2642
- return void 0;
2651
+ return undefined;
2643
2652
  }
2644
2653
  },
2645
2654
  [graphql.Kind.INLINE_FRAGMENT]: {
@@ -2647,7 +2656,7 @@ function subtractSelectionSets(selectionSetA, selectionSetB) {
2647
2656
  if (node.selectionSet?.selections.length === 0) {
2648
2657
  return null;
2649
2658
  }
2650
- return void 0;
2659
+ return undefined;
2651
2660
  }
2652
2661
  }
2653
2662
  });
package/dist/index.js CHANGED
@@ -63,7 +63,7 @@ function getPlanLeftOverFromParent(parent) {
63
63
  if (parent != null && typeof parent === "object") {
64
64
  return parent[PLAN_LEFT_OVER];
65
65
  }
66
- return void 0;
66
+ return undefined;
67
67
  }
68
68
 
69
69
  const UNPATHED_ERRORS_SYMBOL = Symbol.for("subschemaErrors");
@@ -71,7 +71,7 @@ const OBJECT_SUBSCHEMA_SYMBOL = Symbol.for("initialSubschema");
71
71
  const FIELD_SUBSCHEMA_MAP_SYMBOL = Symbol.for("subschemaMap");
72
72
 
73
73
  function isExternalObject(data) {
74
- return data[UNPATHED_ERRORS_SYMBOL] !== void 0;
74
+ return data[UNPATHED_ERRORS_SYMBOL] !== undefined;
75
75
  }
76
76
  function annotateExternalObject(object, errors, subschema, subschemaMap) {
77
77
  Object.defineProperties(object, {
@@ -118,7 +118,7 @@ function mergeFields(mergedTypeInfo, object, sourceSubschema, context, info) {
118
118
  info
119
119
  )
120
120
  ),
121
- void 0
121
+ undefined
122
122
  ),
123
123
  () => object
124
124
  );
@@ -181,7 +181,7 @@ function handleResolverResult(resolverResult, subschema, selectionSet, object, c
181
181
  object[responseKey] = existingPropValue.map(
182
182
  (existingElement, index) => sourcePropValue instanceof Error ? existingElement : mergeDeep(
183
183
  [existingElement, sourcePropValue[index]],
184
- void 0,
184
+ undefined,
185
185
  true,
186
186
  true
187
187
  )
@@ -189,7 +189,7 @@ function handleResolverResult(resolverResult, subschema, selectionSet, object, c
189
189
  } else if (!(sourcePropValue instanceof Error)) {
190
190
  object[responseKey] = mergeDeep(
191
191
  [existingPropValue, sourcePropValue],
192
- void 0,
192
+ undefined,
193
193
  true,
194
194
  true
195
195
  );
@@ -407,7 +407,7 @@ function reportUnpathedErrorsViaNull(unpathedErrors) {
407
407
  if (unreportedErrors.length === 1 && unreportedError) {
408
408
  return locatedError(
409
409
  unreportedError,
410
- void 0,
410
+ undefined,
411
411
  unreportedError.path
412
412
  );
413
413
  }
@@ -418,7 +418,7 @@ function reportUnpathedErrorsViaNull(unpathedErrors) {
418
418
  // locatedError path argument must be defined, but it is just forwarded to a constructor that allows a undefined value
419
419
  // https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/locatedError.js#L25
420
420
  // https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/GraphQLError.js#L19
421
- locatedError(e, void 0, unreportedError?.path)
421
+ locatedError(e, undefined, unreportedError?.path)
422
422
  )
423
423
  ),
424
424
  unreportedErrors.map((error) => error.message).join(", \n")
@@ -448,9 +448,9 @@ function checkResultAndHandleErrors(result = {
448
448
  onLocatedError
449
449
  } = delegationContext;
450
450
  const { data, unpathedErrors } = mergeDataAndErrors(
451
- result.data == null ? void 0 : result.data[responseKey],
451
+ result.data == null ? undefined : result.data[responseKey],
452
452
  result.errors == null ? [] : result.errors,
453
- info != null && info.path ? responsePathAsArray(info.path) : void 0,
453
+ info != null && info.path ? responsePathAsArray(info.path) : undefined,
454
454
  onLocatedError
455
455
  );
456
456
  return resolveExternalValue(
@@ -470,7 +470,7 @@ function mergeDataAndErrors(data, errors, path, onLocatedError, index = 1) {
470
470
  }
471
471
  if (errors.length === 1 && errors[0]) {
472
472
  const error = onLocatedError ? onLocatedError(errors[0]) : errors[0];
473
- const newPath = path === void 0 ? error.path : !error.path ? path : path.concat(error.path.slice(1));
473
+ const newPath = path === undefined ? error.path : !error.path ? path : path.concat(error.path.slice(1));
474
474
  return { data: relocatedError(errors[0], newPath), unpathedErrors: [] };
475
475
  }
476
476
  const combinedError = new AggregateError(
@@ -480,7 +480,7 @@ function mergeDataAndErrors(data, errors, path, onLocatedError, index = 1) {
480
480
  // locatedError path argument must be defined, but it is just forwarded to a constructor that allows a undefined value
481
481
  // https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/locatedError.js#L25
482
482
  // https://github.com/graphql/graphql-js/blob/b4bff0ba9c15c9d7245dd68556e754c41f263289/src/error/GraphQLError.js#L19
483
- locatedError(e, void 0, path)
483
+ locatedError(e, undefined, path)
484
484
  )
485
485
  ),
486
486
  errors.map((error) => error.message).join(", \n")
@@ -496,7 +496,7 @@ function mergeDataAndErrors(data, errors, path, onLocatedError, index = 1) {
496
496
  const pathSegment = error.path?.[index];
497
497
  if (pathSegment != null) {
498
498
  let pathSegmentErrors = errorMap.get(pathSegment);
499
- if (pathSegmentErrors === void 0) {
499
+ if (pathSegmentErrors === undefined) {
500
500
  pathSegmentErrors = [error];
501
501
  errorMap.set(pathSegment, pathSegmentErrors);
502
502
  } else {
@@ -507,7 +507,7 @@ function mergeDataAndErrors(data, errors, path, onLocatedError, index = 1) {
507
507
  }
508
508
  }
509
509
  for (const [pathSegment, pathSegmentErrors] of errorMap) {
510
- if (data[pathSegment] !== void 0) {
510
+ if (data[pathSegment] !== undefined) {
511
511
  const { data: newData, unpathedErrors: newErrors } = mergeDataAndErrors(
512
512
  data[pathSegment],
513
513
  pathSegmentErrors,
@@ -562,7 +562,7 @@ const getTypeInfo = memoize1(function getTypeInfo2(schema) {
562
562
  return new TypeInfo(schema);
563
563
  });
564
564
  const getTypeInfoWithType = memoize2(function getTypeInfoWithType2(schema, type) {
565
- return versionInfo.major < 16 ? new TypeInfo(schema, void 0, type) : new TypeInfo(schema, type);
565
+ return versionInfo.major < 16 ? new TypeInfo(schema, undefined, type) : new TypeInfo(schema, type);
566
566
  });
567
567
 
568
568
  function finalizeGatewayDocument(targetSchema, fragments, operations, onOverlappingAliases, delegationContext) {
@@ -718,7 +718,7 @@ function finalizeGatewayRequest(originalRequest, delegationContext, onOverlappin
718
718
  if (variables != null) {
719
719
  for (const variableName of usedVariables) {
720
720
  const variableValue = variables[variableName];
721
- if (variableValue !== void 0) {
721
+ if (variableValue !== undefined) {
722
722
  newVariables[variableName] = variableValue;
723
723
  }
724
724
  }
@@ -929,9 +929,18 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
929
929
  }
930
930
  if (isUnionType(parentType) && typeInfo.getType() == null) {
931
931
  const possibleTypeNames = [];
932
+ const fieldName = node.name.value;
932
933
  for (const memberType of parentType.getTypes()) {
933
- const possibleField = memberType.getFields()[node.name.value];
934
+ const memberFields = memberType.getFields();
935
+ const possibleField = memberFields[fieldName];
934
936
  if (possibleField != null) {
937
+ const namedType = getNamedType(possibleField.type);
938
+ if (node.selectionSet?.selections?.length && isLeafType(namedType)) {
939
+ continue;
940
+ }
941
+ if (!node.selectionSet?.selections?.length && isCompositeType(namedType)) {
942
+ continue;
943
+ }
935
944
  possibleTypeNames.push(memberType.name);
936
945
  }
937
946
  }
@@ -952,7 +961,7 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
952
961
  }));
953
962
  }
954
963
  }
955
- return void 0;
964
+ return undefined;
956
965
  },
957
966
  leave: (node) => {
958
967
  const type2 = typeInfo.getType();
@@ -960,7 +969,7 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
960
969
  return null;
961
970
  }
962
971
  const namedType = getNamedType(type2);
963
- if (!schema.getType(namedType.name) == null) {
972
+ if (schema.getType(namedType.name) == null) {
964
973
  return null;
965
974
  }
966
975
  if (isObjectType(namedType) || isInterfaceType(namedType)) {
@@ -969,7 +978,7 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
969
978
  return null;
970
979
  }
971
980
  }
972
- return void 0;
981
+ return undefined;
973
982
  }
974
983
  },
975
984
  [Kind.FRAGMENT_SPREAD]: {
@@ -983,7 +992,7 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
983
992
  return null;
984
993
  }
985
994
  usedFragments.push(node.name.value);
986
- return void 0;
995
+ return undefined;
987
996
  }
988
997
  },
989
998
  [Kind.SELECTION_SET]: {
@@ -1019,7 +1028,7 @@ function finalizeSelectionSet(schema, type, validFragments, selectionSet, onOver
1019
1028
  return null;
1020
1029
  }
1021
1030
  }
1022
- return void 0;
1031
+ return undefined;
1023
1032
  },
1024
1033
  leave: (selection, _key, parent) => {
1025
1034
  if (!selection.selectionSet?.selections?.length) {
@@ -1570,7 +1579,7 @@ function wrapConcreteTypes(returnType, targetSchema, document) {
1570
1579
  if (!rootTypeNames.has(typeName)) {
1571
1580
  return false;
1572
1581
  }
1573
- return void 0;
1582
+ return undefined;
1574
1583
  },
1575
1584
  [Kind.FIELD]: (node) => {
1576
1585
  const fieldType = typeInfo.getType();
@@ -1596,7 +1605,7 @@ function wrapConcreteTypes(returnType, targetSchema, document) {
1596
1605
  };
1597
1606
  }
1598
1607
  }
1599
- return void 0;
1608
+ return undefined;
1600
1609
  }
1601
1610
  }),
1602
1611
  // visitorKeys argument usage a la https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-source-graphql/src/batching/merge-queries.js
@@ -1722,7 +1731,7 @@ function createRequest({
1722
1731
  newSelectionSet = selections.length ? {
1723
1732
  kind: Kind.SELECTION_SET,
1724
1733
  selections
1725
- } : void 0;
1734
+ } : undefined;
1726
1735
  const args = fieldNodes?.[0]?.arguments;
1727
1736
  if (args) {
1728
1737
  for (const argNode of args) {
@@ -1744,7 +1753,7 @@ function createRequest({
1744
1753
  varType,
1745
1754
  variableValues?.[varName]
1746
1755
  );
1747
- if (serializedValue !== void 0) {
1756
+ if (serializedValue !== undefined) {
1748
1757
  newVariables[varName] = serializedValue;
1749
1758
  }
1750
1759
  }
@@ -1760,7 +1769,7 @@ function createRequest({
1760
1769
  }
1761
1770
  const fieldNode = fieldNodes?.[0];
1762
1771
  const rootFieldName = targetFieldName ?? fieldNode?.name.value;
1763
- if (rootFieldName === void 0) {
1772
+ if (rootFieldName === undefined) {
1764
1773
  throw new Error(
1765
1774
  `Either "targetFieldName" or a non empty "fieldNodes" array must be provided.`
1766
1775
  );
@@ -1778,7 +1787,7 @@ function createRequest({
1778
1787
  const operationName = targetOperationName ? {
1779
1788
  kind: Kind.NAME,
1780
1789
  value: targetOperationName
1781
- } : void 0;
1790
+ } : undefined;
1782
1791
  const operationDefinition = {
1783
1792
  kind: Kind.OPERATION_DEFINITION,
1784
1793
  name: operationName,
@@ -1825,9 +1834,9 @@ function updateArgumentsWithDefaults(sourceParentType, sourceFieldName, argument
1825
1834
  for (const argument of sourceField.args) {
1826
1835
  const argName = argument.name;
1827
1836
  const sourceArgType = argument.type;
1828
- if (argumentNodeMap[argName] === void 0) {
1837
+ if (argumentNodeMap[argName] === undefined) {
1829
1838
  const defaultValue = argument.defaultValue;
1830
- if (defaultValue !== void 0) {
1839
+ if (defaultValue !== undefined) {
1831
1840
  updateArgument(
1832
1841
  argumentNodeMap,
1833
1842
  variableDefinitionMap,
@@ -1889,7 +1898,7 @@ function defaultMergedResolver(parent, args, context, info) {
1889
1898
  }
1890
1899
  return deferred.promise;
1891
1900
  }
1892
- return void 0;
1901
+ return undefined;
1893
1902
  }
1894
1903
  return handleResult(parent, responseKey, context, info);
1895
1904
  }
@@ -2116,8 +2125,8 @@ function parentSatisfiedSelectionSet(parent, selectionSet) {
2116
2125
  const subschemas2 = /* @__PURE__ */ new Set();
2117
2126
  for (const item of parent) {
2118
2127
  const satisfied = parentSatisfiedSelectionSet(item, selectionSet);
2119
- if (satisfied === void 0) {
2120
- return void 0;
2128
+ if (satisfied === undefined) {
2129
+ return undefined;
2121
2130
  }
2122
2131
  for (const subschema of satisfied) {
2123
2132
  subschemas2.add(subschema);
@@ -2128,15 +2137,15 @@ function parentSatisfiedSelectionSet(parent, selectionSet) {
2128
2137
  if (parent === null) {
2129
2138
  return /* @__PURE__ */ new Set();
2130
2139
  }
2131
- if (parent === void 0) {
2132
- return void 0;
2140
+ if (parent === undefined) {
2141
+ return undefined;
2133
2142
  }
2134
2143
  const subschemas = /* @__PURE__ */ new Set();
2135
2144
  for (const selection of selectionSet.selections) {
2136
2145
  if (selection.kind === Kind.FIELD) {
2137
2146
  const responseKey = selection.alias?.value ?? selection.name.value;
2138
- if (parent[responseKey] === void 0) {
2139
- return void 0;
2147
+ if (parent[responseKey] === undefined) {
2148
+ return undefined;
2140
2149
  }
2141
2150
  if (isExternalObject(parent)) {
2142
2151
  const subschema = getSubschema(parent, responseKey);
@@ -2152,8 +2161,8 @@ function parentSatisfiedSelectionSet(parent, selectionSet) {
2152
2161
  parent[responseKey],
2153
2162
  selection.selectionSet
2154
2163
  );
2155
- if (satisfied === void 0) {
2156
- return void 0;
2164
+ if (satisfied === undefined) {
2165
+ return undefined;
2157
2166
  }
2158
2167
  for (const subschema of satisfied) {
2159
2168
  subschemas.add(subschema);
@@ -2164,8 +2173,8 @@ function parentSatisfiedSelectionSet(parent, selectionSet) {
2164
2173
  parent,
2165
2174
  selection.selectionSet
2166
2175
  );
2167
- if (inlineSatisfied === void 0) {
2168
- return void 0;
2176
+ if (inlineSatisfied === undefined) {
2177
+ return undefined;
2169
2178
  }
2170
2179
  for (const subschema of inlineSatisfied) {
2171
2180
  subschemas.add(subschema);
@@ -2219,7 +2228,7 @@ function isSubschemaConfig(value) {
2219
2228
  function cloneSubschemaConfig(subschemaConfig) {
2220
2229
  const newSubschemaConfig = {
2221
2230
  ...subschemaConfig,
2222
- transforms: subschemaConfig.transforms != null ? [...subschemaConfig.transforms] : void 0
2231
+ transforms: subschemaConfig.transforms != null ? [...subschemaConfig.transforms] : undefined
2223
2232
  };
2224
2233
  if (newSubschemaConfig.merge != null) {
2225
2234
  newSubschemaConfig.merge = { ...subschemaConfig.merge };
@@ -2405,7 +2414,7 @@ function getDelegationContext({
2405
2414
  }
2406
2415
  return {
2407
2416
  subschema: schema,
2408
- subschemaConfig: void 0,
2417
+ subschemaConfig: undefined,
2409
2418
  targetSchema: subschemaOrSubschemaConfig,
2410
2419
  operation,
2411
2420
  fieldName: targetFieldName,
@@ -2631,7 +2640,7 @@ function subtractSelectionSets(selectionSetA, selectionSetB) {
2631
2640
  return null;
2632
2641
  }
2633
2642
  }
2634
- return void 0;
2643
+ return undefined;
2635
2644
  }
2636
2645
  },
2637
2646
  [Kind.SELECTION_SET]: {
@@ -2639,7 +2648,7 @@ function subtractSelectionSets(selectionSetA, selectionSetB) {
2639
2648
  if (node.selections.length === 0) {
2640
2649
  return null;
2641
2650
  }
2642
- return void 0;
2651
+ return undefined;
2643
2652
  }
2644
2653
  },
2645
2654
  [Kind.INLINE_FRAGMENT]: {
@@ -2647,7 +2656,7 @@ function subtractSelectionSets(selectionSetA, selectionSetB) {
2647
2656
  if (node.selectionSet?.selections.length === 0) {
2648
2657
  return null;
2649
2658
  }
2650
- return void 0;
2659
+ return undefined;
2651
2660
  }
2652
2661
  }
2653
2662
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/delegate",
3
- "version": "10.2.9",
3
+ "version": "10.2.10-alpha-e8878e64f4cd1ea558f9ae1848b2e315883294cd",
4
4
  "type": "module",
5
5
  "description": "A set of utils for faster development of GraphQL tools",
6
6
  "repository": {
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "graphql": "^16.9.0",
52
- "pkgroll": "2.6.0"
52
+ "pkgroll": "2.6.1"
53
53
  },
54
54
  "sideEffects": false
55
55
  }