Skip to content

Commit a2ac2a8

Browse files
authored
This fixes the ImmutableMap .map problem where lists can have null inner values (graphql-java#2848)
1 parent d133ec5 commit a2ac2a8

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/main/java/graphql/normalized/ValueToVariableValueCompiler.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.List;
2323
import java.util.Map;
2424

25-
import static graphql.collect.ImmutableKit.map;
2625
import static java.util.stream.Collectors.toList;
2726

2827
@Internal
@@ -66,13 +65,15 @@ static Object normalisedValueToVariableValue(Object maybeValue) {
6665
} else if (maybeValue instanceof Map) {
6766
variableValue = normalisedValueToVariableValues((Map<String, Object>) maybeValue);
6867
} else {
69-
throw new AssertException("Should never happen. Did not expect type: " + maybeClass(maybeValue));
68+
throw new AssertException("Should never happen. Did not expect type: " + maybeClass(maybeValue));
7069
}
7170
return variableValue;
7271
}
7372

7473
private static List<Object> normalisedValueToVariableValues(List<Object> arrayValues) {
75-
return map(arrayValues, ValueToVariableValueCompiler::normalisedValueToVariableValue);
74+
return arrayValues.stream()
75+
.map(ValueToVariableValueCompiler::normalisedValueToVariableValue)
76+
.collect(toList());
7677
}
7778

7879
@NotNull

src/test/groovy/graphql/normalized/ValueToVariableValueCompilerTest.groovy

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import graphql.language.NullValue
1111
import graphql.language.ObjectField
1212
import graphql.language.ObjectValue
1313
import graphql.language.StringValue
14-
import graphql.language.Type
1514
import graphql.language.TypeName
1615
import graphql.schema.idl.TypeUtil
1716
import spock.lang.Specification
@@ -89,6 +88,18 @@ class ValueToVariableValueCompilerTest extends Specification {
8988
// but for now this is what we do
9089
}
9190

91+
def "can handle NormalizedInputValue values that are NIV with null members"() {
92+
expect:
93+
def niv = new NormalizedInputValue("TypeName", value)
94+
def actual = ValueToVariableValueCompiler.normalisedValueToVariableValue(niv)
95+
actual == expected
96+
97+
where:
98+
value | expected
99+
[a: new NormalizedInputValue("X", IntValue.of(666)), b: new NormalizedInputValue("X", null)] | [a: 666, b: null]
100+
[new NormalizedInputValue("X", IntValue.of(666)), new NormalizedInputValue("X", null)] | [666, null]
101+
}
102+
92103

93104
def "can print variables as expected"() {
94105
expect:
@@ -100,7 +111,7 @@ class ValueToVariableValueCompilerTest extends Specification {
100111
// compare actual type
101112
def actualType = actual.definition.type
102113
actualType.isEqualTo(expectedType)
103-
if(actualType instanceof NonNullType || actualType instanceof ListType){
114+
if (actualType instanceof NonNullType || actualType instanceof ListType) {
104115
actualType.type.isEqualTo(expectedType.type)
105116
}
106117
TypeUtil.simplePrint(actualType) == typeName
@@ -113,8 +124,8 @@ class ValueToVariableValueCompilerTest extends Specification {
113124
BooleanValue.of(true) | 4 | "Boolean!" | true | "v4" | new NonNullType(new TypeName("Boolean"))
114125
FloatValue.of(999d) | 5 | "Float" | 999d | "v5" | new TypeName("Float")
115126
EnumValue.of("enumValue") | 6 | "Foo!" | "enumValue" | "v6" | new NonNullType(new TypeName("Foo"))
116-
["a" : IntValue.of(64),
117-
"b":IntValue.of(65) ] | 7 | "ObjectType" | [a: 64, b: 65] | "v7" | new TypeName("ObjectType")
127+
["a": IntValue.of(64),
128+
"b": IntValue.of(65)] | 7 | "ObjectType" | [a: 64, b: 65] | "v7" | new TypeName("ObjectType")
118129
[StringValue.of("9"),
119130
StringValue.of("10"),
120131
StringValue.of("11")] | 8 | "[String]" | ["9", "10", "11"] | "v8" | new ListType((new TypeName("String")))

0 commit comments

Comments
 (0)