Skip to content

Commit

Permalink
fix(delegate): handle existing argument nodes correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Dec 7, 2022
1 parent b5e6459 commit 13c2488
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/cold-files-drive.md
@@ -0,0 +1,6 @@
---
'@graphql-tools/delegate': patch
'@graphql-tools/utils': patch
---

Fix handling argument values in gateway request
11 changes: 10 additions & 1 deletion packages/delegate/src/finalizeGatewayRequest.ts
Expand Up @@ -16,6 +16,7 @@ import {
SelectionSetNode,
TypeInfo,
TypeNameMetaFieldDef,
valueFromAST,
VariableDefinitionNode,
versionInfo as graphqlVersionInfo,
visit,
Expand Down Expand Up @@ -221,14 +222,22 @@ function updateArguments(
const argType = argument.type;

if (argName in newArgs) {
let value: any;
const existingValueNode = argumentNodeMap[argName]?.value;
if (existingValueNode != null) {
value = valueFromAST(existingValueNode, argType, variableValues);
}
if (value == null) {
value = serializeInputValue(argType, newArgs[argName]);
}
updateArgument(
argumentNodeMap,
variableDefinitionMap,
variableValues,
argName,
generateVariableName(argName),
argType,
serializeInputValue(argType, newArgs[argName])
value
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/src/transformInputValue.ts
@@ -1,4 +1,5 @@
import { GraphQLInputType, getNullableType, isLeafType, isListType, isInputObjectType } from 'graphql';
import { asArray } from './helpers.js';

import { InputLeafValueTransformer, InputObjectValueTransformer, Maybe } from './types.js';

Expand All @@ -17,7 +18,7 @@ export function transformInputValue(
if (isLeafType(nullableType)) {
return inputLeafValueTransformer != null ? inputLeafValueTransformer(nullableType, value) : value;
} else if (isListType(nullableType)) {
return value.map((listMember: any) =>
return asArray(value).map((listMember: any) =>
transformInputValue(nullableType.ofType, listMember, inputLeafValueTransformer, inputObjectValueTransformer)
);
} else if (isInputObjectType(nullableType)) {
Expand Down

0 comments on commit 13c2488

Please sign in to comment.