Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when NullValue is nested inside ObjectValue #91

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/graphql/scalars/object/ObjectScalar.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public Object parseValue(Object input) throws CoercingParseValueException {
@Override
public Object parseLiteral(Object input) throws CoercingParseLiteralException {
// on purpose - object scalars can be null
//noinspection ConstantConditions
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDE said this is redundant

return parseLiteral(input, Collections.emptyMap());
}

Expand Down Expand Up @@ -94,7 +93,12 @@ public Object parseLiteral(Object input, Map<String, Object> variables) throws C
List<ObjectField> values = ((ObjectValue) input).getObjectFields();
Map<String, Object> parsedValues = new LinkedHashMap<>();
values.forEach(fld -> {
Object parsedValue = parseLiteral(fld.getValue(), variables);
Object parsedValue;
if (fld.getValue() instanceof NullValue) { // Nested NullValue inside ObjectValue
parsedValue = null;
} else {
parsedValue = parseLiteral(fld.getValue(), variables);
}
parsedValues.put(fld.getName(), parsedValue);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall Object value is guaranteed not to be NullValue as this is handled earlier in GraphQL Java, however it may contain a nested NullValue.

});
return parsedValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class ObjectScalarTest extends Specification {
childFl2 : mkVarRef("varRef1")
] as Map<String, Value>)
] as Map<String, Value>) | [fld1: "s", fld2: 99, fld3: [childFld1: "child1", childFl2: "value1"]]

mkObjectValue([
field1: mkNullValue()
] as Map<String, Value>) | [field1: null] // Nested NullValue inside ObjectValue
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails with the old behaviour, and passes with the new behaviour

}

@Unroll
Expand Down