Skip to content

Commit babda5f

Browse files
authored
Merge pull request #91 from graphql-java/object-scalar-null-fix
Fix bug when NullValue is nested inside ObjectValue
2 parents 8bb2279 + 88e9fec commit babda5f

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/main/java/graphql/scalars/object/ObjectScalar.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public Object parseValue(Object input) throws CoercingParseValueException {
5454
@Override
5555
public Object parseLiteral(Object input) throws CoercingParseLiteralException {
5656
// on purpose - object scalars can be null
57-
//noinspection ConstantConditions
5857
return parseLiteral(input, Collections.emptyMap());
5958
}
6059

@@ -94,7 +93,12 @@ public Object parseLiteral(Object input, Map<String, Object> variables) throws C
9493
List<ObjectField> values = ((ObjectValue) input).getObjectFields();
9594
Map<String, Object> parsedValues = new LinkedHashMap<>();
9695
values.forEach(fld -> {
97-
Object parsedValue = parseLiteral(fld.getValue(), variables);
96+
Object parsedValue;
97+
if (fld.getValue() instanceof NullValue) { // Nested NullValue inside ObjectValue
98+
parsedValue = null;
99+
} else {
100+
parsedValue = parseLiteral(fld.getValue(), variables);
101+
}
98102
parsedValues.put(fld.getName(), parsedValue);
99103
});
100104
return parsedValues;

src/test/groovy/graphql/scalars/object/ObjectScalarTest.groovy

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class ObjectScalarTest extends Specification {
6060
childFl2 : mkVarRef("varRef1")
6161
] as Map<String, Value>)
6262
] as Map<String, Value>) | [fld1: "s", fld2: 99, fld3: [childFld1: "child1", childFl2: "value1"]]
63+
64+
mkObjectValue([
65+
field1: mkNullValue()
66+
] as Map<String, Value>) | [field1: null] // Nested NullValue inside ObjectValue
6367
}
6468

6569
@Unroll

0 commit comments

Comments
 (0)