Skip to content

Commit

Permalink
Fix NPE when coercing null enum value in BatchedExecutionStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine Boyer committed Mar 25, 2016
1 parent 4a908db commit 359a8e6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private GraphQLObjectType getGraphQLObjectType(GraphQLType fieldType, Object val
private void handlePrimitives(List<GraphQLExecutionNodeValue> values, String fieldName,
GraphQLType type) {
for (GraphQLExecutionNodeValue value : values) {
Object coercedValue = coerce(type, value.getValue());
Object coercedValue = value.getValue() == null ? null : coerce(type, value.getValue());
value.getResultContainer().putResult(fieldName, coercedValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import graphql.schema.GraphQLArgument;
import graphql.schema.GraphQLEnumType;
import graphql.schema.GraphQLFieldDefinition;
import graphql.schema.GraphQLList;
import graphql.schema.GraphQLNonNull;
Expand Down Expand Up @@ -290,6 +291,23 @@ GraphQLSchema createSchema() {

.build();


GraphQLEnumType enumDayType = GraphQLEnumType.newEnum()
.name("Day")
.value("MONDAY")
.value("TUESDAY")
.description("Day of the week")
.build();

GraphQLObjectType enumObjectType = GraphQLObjectType.newObject()
.name("EnumObject")
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("value")
.type(enumDayType)
.dataFetcher(stringObjectValueFetcher)
.build())
.build();

GraphQLObjectType queryType = GraphQLObjectType.newObject()
.name("StringQuery")
.field(GraphQLFieldDefinition.newFieldDefinition()
Expand All @@ -304,6 +322,19 @@ GraphQLSchema createSchema() {
public Object get(DataFetchingEnvironment env) {return env.getArgument("value");}
})
.build())
.name("EnumQuery")
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("enum")
.type(enumObjectType)
.argument(GraphQLArgument.newArgument()
.name("value")
.type(Scalars.GraphQLString)
.build())
.dataFetcher(new DataFetcher() {
@Override
public Object get(DataFetchingEnvironment env) {return env.getArgument("value");}
})
.build())
.build();
return GraphQLSchema.newSchema()
.query(queryType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ class GraphqlExecutionSpec extends Specification {

}

def "Legal null value for enum"() {

given:
String query =
"{ enum(value: \"null\") { value } }";

Map<String, Object> expected = mapOf(
"enum", mapOf("value", null));

expect:
runTest(query, expected);

}

def "Illegal null value for primitives"() {

given:
Expand Down

0 comments on commit 359a8e6

Please sign in to comment.