Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
fix(delegation): do not override null defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Mar 27, 2020
1 parent 0b1477c commit 3224224
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/delegate/createRequest.ts
Expand Up @@ -174,10 +174,10 @@ function updateArgumentsWithDefaults(
const argName = argument.name;
const sourceArgType = argument.type;

if (argumentNodeMap[argName] == null) {
if (argumentNodeMap[argName] === undefined) {
const defaultValue = argument.defaultValue;

if (defaultValue != null) {
if (defaultValue !== undefined) {
updateArgument(
argName,
sourceArgType,
Expand Down
2 changes: 1 addition & 1 deletion src/polyfills/toConfig.ts
Expand Up @@ -134,7 +134,7 @@ export function toConfig(graphqlObject: any) {
graphqlObject.subscribe != null
) {
return fieldToConfig(graphqlObject);
} else if (graphqlObject.defaultValue != null) {
} else if (graphqlObject.defaultValue !== undefined) {
return inputFieldToConfig(graphqlObject);
}

Expand Down
55 changes: 27 additions & 28 deletions src/wrap/transforms/AddArgumentsAsVariables.ts
Expand Up @@ -84,13 +84,16 @@ function addVariablesToRootField(

const targetField = type.getFields()[selection.name.value];

updateArguments(
targetField,
argumentNodeMap,
variableDefinitionMap,
variableValues,
args,
);
// excludes __typename
if (targetField != null) {
updateArguments(
targetField,
argumentNodeMap,
variableDefinitionMap,
variableValues,
args,
);
}

newSelectionSet.push({
...selection,
Expand Down Expand Up @@ -124,32 +127,28 @@ function addVariablesToRootField(
};
}

const hasOwn = Object.prototype.hasOwnProperty;

function updateArguments(
targetField: GraphQLField<any, any>,
argumentNodeMap: Record<string, ArgumentNode>,
variableDefinitionMap: Record<string, VariableDefinitionNode>,
variableValues: Record<string, any>,
newArgs: Record<string, any>,
): void {
if (targetField != null) {
targetField.args.forEach((argument: GraphQLArgument) => {
const argName = argument.name;
const argType = argument.type;

if (newArgs[argName] != null) {
const newArg = newArgs[argName];

if (newArg != null) {
updateArgument(
argName,
argType,
argumentNodeMap,
variableDefinitionMap,
variableValues,
serializeInputValue(argType, newArg),
);
}
}
});
}
targetField.args.forEach((argument: GraphQLArgument) => {
const argName = argument.name;
const argType = argument.type;

if (hasOwn.call(newArgs, argName)) {
updateArgument(
argName,
argType,
argumentNodeMap,
variableDefinitionMap,
variableValues,
serializeInputValue(argType, newArgs[argName]),
);
}
});
}

0 comments on commit 3224224

Please sign in to comment.