@graphql-tools/delegate 12.1.1 → 12.1.2

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,12 @@
1
1
  # @graphql-tools/delegate
2
2
 
3
+ ## 12.1.2
4
+ ### Patch Changes
5
+
6
+
7
+
8
+ - [#2544](https://github.com/graphql-hive/gateway/pull/2544) [`af2cccb`](https://github.com/graphql-hive/gateway/commit/af2cccb7150db504ce42ab6b463166341377614f) Thanks [@egoodwinx](https://github.com/egoodwinx)! - Create new getCoercedVariableValues to support graphql-js 17
9
+
3
10
  ## 12.1.1
4
11
  ### Patch Changes
5
12
 
package/dist/index.cjs CHANGED
@@ -57,6 +57,16 @@ class Subschema {
57
57
  }
58
58
  }
59
59
 
60
+ function getCoercedVariableValues(variableValues) {
61
+ if (variableValues == null) {
62
+ return void 0;
63
+ }
64
+ if (Object.hasOwn(variableValues, "coerced") && Object.hasOwn(variableValues, "sources")) {
65
+ return variableValues.coerced;
66
+ }
67
+ return variableValues;
68
+ }
69
+
60
70
  const prototypePollutingKeys = [
61
71
  "__proto__",
62
72
  "constructor",
@@ -102,10 +112,11 @@ const getActualFieldNodes = utils.memoize1(function(fieldNode) {
102
112
  return [fieldNode];
103
113
  });
104
114
  function mergeFields(mergedTypeInfo, object, sourceSubschema, context, info) {
115
+ const variableValues = getCoercedVariableValues(info.variableValues);
105
116
  const delegationMaps = mergedTypeInfo.delegationPlanBuilder(
106
117
  info.schema,
107
118
  sourceSubschema,
108
- info.variableValues != null && Object.keys(info.variableValues).length > 0 ? info.variableValues : EMPTY_OBJECT,
119
+ variableValues != null && Object.keys(variableValues).length > 0 ? variableValues : EMPTY_OBJECT,
109
120
  info.fragments != null && Object.keys(info.fragments).length > 0 ? info.fragments : EMPTY_OBJECT,
110
121
  info.fieldNodes?.length ? info.fieldNodes.length === 1 && info.fieldNodes[0] ? getActualFieldNodes(info.fieldNodes[0]) : info.fieldNodes : EMPTY_ARRAY,
111
122
  context,
@@ -137,7 +148,7 @@ function handleResolverResult(resolverResult, subschema, selectionSet, object, c
137
148
  const { fields } = utils.collectFields(
138
149
  schema,
139
150
  info.fragments,
140
- info.variableValues,
151
+ getCoercedVariableValues(info.variableValues) ?? EMPTY_OBJECT,
141
152
  type,
142
153
  selectionSet
143
154
  );
@@ -821,7 +832,9 @@ function finalizeGatewayRequest(originalRequest, delegationContext, onOverlappin
821
832
  delegationContext
822
833
  );
823
834
  const newVariables = {};
824
- const outerVariables = delegationContext.info?.variableValues;
835
+ const outerVariables = getCoercedVariableValues(
836
+ delegationContext.info?.variableValues
837
+ );
825
838
  for (const varName of usedVariables) {
826
839
  const existingVar = originalRequest.variables?.[varName];
827
840
  const outerVar = outerVariables?.[varName];
@@ -2341,7 +2354,8 @@ function createRequest({
2341
2354
  `Either "targetFieldName" or a non empty "fieldNodes" array must be provided.`
2342
2355
  );
2343
2356
  }
2344
- const newVariables = info?.variableValues ? { ...info.variableValues } : {};
2357
+ const outerVariableValues = getCoercedVariableValues(info?.variableValues);
2358
+ const newVariables = outerVariableValues ? { ...outerVariableValues } : {};
2345
2359
  const variableDefinitions = info?.operation.variableDefinitions ? [...info.operation.variableDefinitions] : [];
2346
2360
  const argNodes = [];
2347
2361
  const replacedVariableNames = /* @__PURE__ */ new Set();
@@ -2382,7 +2396,7 @@ function createRequest({
2382
2396
  ) || // It should not conflict with the variable on the gateway request
2383
2397
  // Because the gateway request can have a variable that has nothing to do with
2384
2398
  // this argument
2385
- info?.variableValues?.[varName2] != null;
2399
+ outerVariableValues?.[varName2] != null;
2386
2400
  let varName = argName;
2387
2401
  if (varExists(varName)) {
2388
2402
  varName = `_${rootFieldName}_${argName}`;
@@ -2717,10 +2731,13 @@ function handleFlattenedParent(flattenedParent, leftOverParent, possibleSubschem
2717
2731
  responseKey
2718
2732
  );
2719
2733
  if (sourceSubschema && nestedTypeName) {
2734
+ const variableValues = getCoercedVariableValues(
2735
+ info.variableValues
2736
+ );
2720
2737
  const delegationPlan = stitchingInfo.mergedTypes[nestedTypeName]?.delegationPlanBuilder(
2721
2738
  info.schema,
2722
2739
  sourceSubschema,
2723
- info.variableValues != null && Object.keys(info.variableValues).length > 0 ? info.variableValues : EMPTY_OBJECT,
2740
+ variableValues != null && Object.keys(variableValues).length > 0 ? variableValues : EMPTY_OBJECT,
2724
2741
  info.fragments != null && Object.keys(info.fragments).length > 0 ? info.fragments : EMPTY_OBJECT,
2725
2742
  getActualFieldNodes(fieldNode),
2726
2743
  context,
package/dist/index.js CHANGED
@@ -57,6 +57,16 @@ class Subschema {
57
57
  }
58
58
  }
59
59
 
60
+ function getCoercedVariableValues(variableValues) {
61
+ if (variableValues == null) {
62
+ return void 0;
63
+ }
64
+ if (Object.hasOwn(variableValues, "coerced") && Object.hasOwn(variableValues, "sources")) {
65
+ return variableValues.coerced;
66
+ }
67
+ return variableValues;
68
+ }
69
+
60
70
  const prototypePollutingKeys = [
61
71
  "__proto__",
62
72
  "constructor",
@@ -102,10 +112,11 @@ const getActualFieldNodes = memoize1(function(fieldNode) {
102
112
  return [fieldNode];
103
113
  });
104
114
  function mergeFields(mergedTypeInfo, object, sourceSubschema, context, info) {
115
+ const variableValues = getCoercedVariableValues(info.variableValues);
105
116
  const delegationMaps = mergedTypeInfo.delegationPlanBuilder(
106
117
  info.schema,
107
118
  sourceSubschema,
108
- info.variableValues != null && Object.keys(info.variableValues).length > 0 ? info.variableValues : EMPTY_OBJECT,
119
+ variableValues != null && Object.keys(variableValues).length > 0 ? variableValues : EMPTY_OBJECT,
109
120
  info.fragments != null && Object.keys(info.fragments).length > 0 ? info.fragments : EMPTY_OBJECT,
110
121
  info.fieldNodes?.length ? info.fieldNodes.length === 1 && info.fieldNodes[0] ? getActualFieldNodes(info.fieldNodes[0]) : info.fieldNodes : EMPTY_ARRAY,
111
122
  context,
@@ -137,7 +148,7 @@ function handleResolverResult(resolverResult, subschema, selectionSet, object, c
137
148
  const { fields } = collectFields(
138
149
  schema,
139
150
  info.fragments,
140
- info.variableValues,
151
+ getCoercedVariableValues(info.variableValues) ?? EMPTY_OBJECT,
141
152
  type,
142
153
  selectionSet
143
154
  );
@@ -821,7 +832,9 @@ function finalizeGatewayRequest(originalRequest, delegationContext, onOverlappin
821
832
  delegationContext
822
833
  );
823
834
  const newVariables = {};
824
- const outerVariables = delegationContext.info?.variableValues;
835
+ const outerVariables = getCoercedVariableValues(
836
+ delegationContext.info?.variableValues
837
+ );
825
838
  for (const varName of usedVariables) {
826
839
  const existingVar = originalRequest.variables?.[varName];
827
840
  const outerVar = outerVariables?.[varName];
@@ -2341,7 +2354,8 @@ function createRequest({
2341
2354
  `Either "targetFieldName" or a non empty "fieldNodes" array must be provided.`
2342
2355
  );
2343
2356
  }
2344
- const newVariables = info?.variableValues ? { ...info.variableValues } : {};
2357
+ const outerVariableValues = getCoercedVariableValues(info?.variableValues);
2358
+ const newVariables = outerVariableValues ? { ...outerVariableValues } : {};
2345
2359
  const variableDefinitions = info?.operation.variableDefinitions ? [...info.operation.variableDefinitions] : [];
2346
2360
  const argNodes = [];
2347
2361
  const replacedVariableNames = /* @__PURE__ */ new Set();
@@ -2382,7 +2396,7 @@ function createRequest({
2382
2396
  ) || // It should not conflict with the variable on the gateway request
2383
2397
  // Because the gateway request can have a variable that has nothing to do with
2384
2398
  // this argument
2385
- info?.variableValues?.[varName2] != null;
2399
+ outerVariableValues?.[varName2] != null;
2386
2400
  let varName = argName;
2387
2401
  if (varExists(varName)) {
2388
2402
  varName = `_${rootFieldName}_${argName}`;
@@ -2717,10 +2731,13 @@ function handleFlattenedParent(flattenedParent, leftOverParent, possibleSubschem
2717
2731
  responseKey
2718
2732
  );
2719
2733
  if (sourceSubschema && nestedTypeName) {
2734
+ const variableValues = getCoercedVariableValues(
2735
+ info.variableValues
2736
+ );
2720
2737
  const delegationPlan = stitchingInfo.mergedTypes[nestedTypeName]?.delegationPlanBuilder(
2721
2738
  info.schema,
2722
2739
  sourceSubschema,
2723
- info.variableValues != null && Object.keys(info.variableValues).length > 0 ? info.variableValues : EMPTY_OBJECT,
2740
+ variableValues != null && Object.keys(variableValues).length > 0 ? variableValues : EMPTY_OBJECT,
2724
2741
  info.fragments != null && Object.keys(info.fragments).length > 0 ? info.fragments : EMPTY_OBJECT,
2725
2742
  getActualFieldNodes(fieldNode),
2726
2743
  context,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/delegate",
3
- "version": "12.1.1",
3
+ "version": "12.1.2",
4
4
  "type": "module",
5
5
  "description": "A set of utils for faster development of GraphQL tools",
6
6
  "repository": {