@graphql-tools/delegate 12.0.19 → 12.0.20-alpha-c35121316ffa963b01e5550763795df2a3c493df

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,14 @@
1
1
  # @graphql-tools/delegate
2
2
 
3
+ ## 12.0.20-alpha-c35121316ffa963b01e5550763795df2a3c493df
4
+ ### Patch Changes
5
+
6
+
7
+
8
+ - [#2474](https://github.com/graphql-hive/gateway/pull/2474) [`c351213`](https://github.com/graphql-hive/gateway/commit/c35121316ffa963b01e5550763795df2a3c493df) Thanks [@enisdenjo](https://github.com/enisdenjo)! - Fix delegated argument variable type compatibility
9
+
10
+ Avoid reusing variables whose types are incompatible with target schema argument types, and create correctly typed variables instead.
11
+
3
12
  ## 12.0.19
4
13
  ### Patch Changes
5
14
 
package/dist/index.cjs CHANGED
@@ -2354,10 +2354,18 @@ function createRequest({
2354
2354
  const existingArgNode = fieldNode?.arguments?.find(
2355
2355
  (argNode) => argNode.name.value === argName
2356
2356
  );
2357
- if (existingArgNode?.value.kind === graphql.Kind.VARIABLE) {
2357
+ if (existingArgNode?.value.kind === graphql.Kind.VARIABLE && argInstance) {
2358
2358
  const varName = existingArgNode.value.name.value;
2359
2359
  const varValue = newVariables[varName];
2360
- if (varValue === argValue) {
2360
+ const variableDefinition = variableDefinitions.find(
2361
+ (definition) => definition.variable.name.value === varName
2362
+ );
2363
+ const variableType = variableDefinition && targetSchema ? graphql.typeFromAST(info?.schema ?? targetSchema, variableDefinition.type) : void 0;
2364
+ if (varValue === argValue && variableType && graphql.isTypeSubTypeOf(
2365
+ info?.schema ?? targetSchema,
2366
+ variableType,
2367
+ argInstance.type
2368
+ )) {
2361
2369
  argNodes.push(existingArgNode);
2362
2370
  continue;
2363
2371
  }
@@ -2378,6 +2386,16 @@ function createRequest({
2378
2386
  varName = `_${i++}_${rootFieldName}_${argName}`;
2379
2387
  }
2380
2388
  }
2389
+ if (existingArgNode?.value.kind === graphql.Kind.VARIABLE) {
2390
+ const existingVarName = existingArgNode.value.name.value;
2391
+ const existingVarIndex = variableDefinitions.findIndex(
2392
+ (definition) => definition.variable.name.value === existingVarName
2393
+ );
2394
+ if (existingVarIndex !== -1) {
2395
+ variableDefinitions.splice(existingVarIndex, 1);
2396
+ delete newVariables[existingVarName];
2397
+ }
2398
+ }
2381
2399
  variableDefinitions.push({
2382
2400
  kind: graphql.Kind.VARIABLE_DEFINITION,
2383
2401
  variable: {
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { memoize2, memoize1, collectFields, relocatedError, mergeDeep, promiseReduce, pathToArray, getResponseKeyFromInfo, memoize3, getDefinedRootType, createGraphQLError, implementsAbstractType, getRootTypeNames, astFromArg, astFromValueUntyped, asArray, isAsyncIterable, getOperationASTFromRequest } from '@graphql-tools/utils';
2
2
  export { createDeferred } from '@graphql-tools/utils';
3
- import { GraphQLError, locatedError, isAbstractType, getNullableType, isLeafType, isCompositeType, isListType, responsePathAsArray, Kind, TypeInfo, versionInfo, visit, visitWithTypeInfo, isNullableType, isUnionType, getNamedType, isObjectType, isInterfaceType, isNonNullType, isInputObjectType, defaultFieldResolver, isSchema, validate } from 'graphql';
3
+ import { GraphQLError, locatedError, isAbstractType, getNullableType, isLeafType, isCompositeType, isListType, responsePathAsArray, Kind, TypeInfo, versionInfo, visit, visitWithTypeInfo, isNullableType, isUnionType, getNamedType, isObjectType, isInterfaceType, typeFromAST, isTypeSubTypeOf, isNonNullType, isInputObjectType, defaultFieldResolver, isSchema, validate } from 'graphql';
4
4
  import { handleMaybePromise, isPromise, createDeferredPromise, mapAsyncIterator } from '@whatwg-node/promise-helpers';
5
5
  import { CRITICAL_ERROR, executorFromSchema } from '@graphql-tools/executor';
6
6
  export { executorFromSchema as createDefaultExecutor } from '@graphql-tools/executor';
@@ -2354,10 +2354,18 @@ function createRequest({
2354
2354
  const existingArgNode = fieldNode?.arguments?.find(
2355
2355
  (argNode) => argNode.name.value === argName
2356
2356
  );
2357
- if (existingArgNode?.value.kind === Kind.VARIABLE) {
2357
+ if (existingArgNode?.value.kind === Kind.VARIABLE && argInstance) {
2358
2358
  const varName = existingArgNode.value.name.value;
2359
2359
  const varValue = newVariables[varName];
2360
- if (varValue === argValue) {
2360
+ const variableDefinition = variableDefinitions.find(
2361
+ (definition) => definition.variable.name.value === varName
2362
+ );
2363
+ const variableType = variableDefinition && targetSchema ? typeFromAST(info?.schema ?? targetSchema, variableDefinition.type) : void 0;
2364
+ if (varValue === argValue && variableType && isTypeSubTypeOf(
2365
+ info?.schema ?? targetSchema,
2366
+ variableType,
2367
+ argInstance.type
2368
+ )) {
2361
2369
  argNodes.push(existingArgNode);
2362
2370
  continue;
2363
2371
  }
@@ -2378,6 +2386,16 @@ function createRequest({
2378
2386
  varName = `_${i++}_${rootFieldName}_${argName}`;
2379
2387
  }
2380
2388
  }
2389
+ if (existingArgNode?.value.kind === Kind.VARIABLE) {
2390
+ const existingVarName = existingArgNode.value.name.value;
2391
+ const existingVarIndex = variableDefinitions.findIndex(
2392
+ (definition) => definition.variable.name.value === existingVarName
2393
+ );
2394
+ if (existingVarIndex !== -1) {
2395
+ variableDefinitions.splice(existingVarIndex, 1);
2396
+ delete newVariables[existingVarName];
2397
+ }
2398
+ }
2381
2399
  variableDefinitions.push({
2382
2400
  kind: Kind.VARIABLE_DEFINITION,
2383
2401
  variable: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/delegate",
3
- "version": "12.0.19",
3
+ "version": "12.0.20-alpha-c35121316ffa963b01e5550763795df2a3c493df",
4
4
  "type": "module",
5
5
  "description": "A set of utils for faster development of GraphQL tools",
6
6
  "repository": {