Skip to content

Commit 13c2488

Browse files
committed
fix(delegate): handle existing argument nodes correctly
1 parent b5e6459 commit 13c2488

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

.changeset/cold-files-drive.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-tools/delegate': patch
3+
'@graphql-tools/utils': patch
4+
---
5+
6+
Fix handling argument values in gateway request

packages/delegate/src/finalizeGatewayRequest.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
SelectionSetNode,
1717
TypeInfo,
1818
TypeNameMetaFieldDef,
19+
valueFromAST,
1920
VariableDefinitionNode,
2021
versionInfo as graphqlVersionInfo,
2122
visit,
@@ -221,14 +222,22 @@ function updateArguments(
221222
const argType = argument.type;
222223

223224
if (argName in newArgs) {
225+
let value: any;
226+
const existingValueNode = argumentNodeMap[argName]?.value;
227+
if (existingValueNode != null) {
228+
value = valueFromAST(existingValueNode, argType, variableValues);
229+
}
230+
if (value == null) {
231+
value = serializeInputValue(argType, newArgs[argName]);
232+
}
224233
updateArgument(
225234
argumentNodeMap,
226235
variableDefinitionMap,
227236
variableValues,
228237
argName,
229238
generateVariableName(argName),
230239
argType,
231-
serializeInputValue(argType, newArgs[argName])
240+
value
232241
);
233242
}
234243
}

packages/utils/src/transformInputValue.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { GraphQLInputType, getNullableType, isLeafType, isListType, isInputObjectType } from 'graphql';
2+
import { asArray } from './helpers.js';
23

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

@@ -17,7 +18,7 @@ export function transformInputValue(
1718
if (isLeafType(nullableType)) {
1819
return inputLeafValueTransformer != null ? inputLeafValueTransformer(nullableType, value) : value;
1920
} else if (isListType(nullableType)) {
20-
return value.map((listMember: any) =>
21+
return asArray(value).map((listMember: any) =>
2122
transformInputValue(nullableType.ofType, listMember, inputLeafValueTransformer, inputObjectValueTransformer)
2223
);
2324
} else if (isInputObjectType(nullableType)) {

0 commit comments

Comments
 (0)