Skip to content

Commit 8987ac6

Browse files
bbakermanandimarek
authored andcommitted
Now follows spec as discussed
1 parent 158c48d commit 8987ac6

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

src/main/java/graphql/execution/ValuesResolver.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import graphql.language.Value;
1111
import graphql.language.VariableDefinition;
1212
import graphql.language.VariableReference;
13+
import graphql.schema.CoercingParseValueException;
1314
import graphql.schema.GraphQLArgument;
1415
import graphql.schema.GraphQLEnumType;
1516
import graphql.schema.GraphQLInputObjectField;
@@ -145,19 +146,23 @@ private Object coerceValue(VariableDefinition variableDefinition, GraphQLType gr
145146
return returnValue;
146147
}
147148

148-
if (value == null) return null;
149+
if (value == null) {
150+
return null;
151+
}
149152

150153
if (graphQLType instanceof GraphQLScalarType) {
151154
return coerceValueForScalar((GraphQLScalarType) graphQLType, value);
152155
} else if (graphQLType instanceof GraphQLEnumType) {
153156
return coerceValueForEnum((GraphQLEnumType) graphQLType, value);
154157
} else if (graphQLType instanceof GraphQLList) {
155158
return coerceValueForList(variableDefinition, (GraphQLList) graphQLType, value);
156-
} else if (graphQLType instanceof GraphQLInputObjectType && value instanceof Map) {
157-
//noinspection unchecked
158-
return coerceValueForInputObjectType(variableDefinition, (GraphQLInputObjectType) graphQLType, (Map<String, Object>) value);
159159
} else if (graphQLType instanceof GraphQLInputObjectType) {
160-
return value;
160+
if (value instanceof Map) {
161+
//noinspection unchecked
162+
return coerceValueForInputObjectType(variableDefinition, (GraphQLInputObjectType) graphQLType, (Map<String, Object>) value);
163+
} else {
164+
throw new CoercingParseValueException("Variables for GraphQLInputObjectType must be an instance of a Map according to the graphql specification. The offending object was a " + value.getClass().getName());
165+
}
161166
} else {
162167
return assertShouldNeverHappen("unhandled type " + graphQLType);
163168
}

src/test/groovy/graphql/Issue739.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package graphql
22

3+
import graphql.schema.CoercingParseValueException
34
import graphql.schema.GraphQLObjectType
45
import graphql.schema.idl.RuntimeWiring
56
import spock.lang.Specification
@@ -85,6 +86,6 @@ class Issue739 extends Specification {
8586
.join()
8687

8788
then:
88-
1 == varResult.getErrors().size()
89+
thrown(CoercingParseValueException)
8990
}
9091
}

src/test/groovy/graphql/execution/ValuesResolverTest.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import graphql.language.TypeName
1616
import graphql.language.Value
1717
import graphql.language.VariableDefinition
1818
import graphql.language.VariableReference
19+
import graphql.schema.CoercingParseValueException
1920
import graphql.schema.GraphQLArgument
2021
import graphql.schema.GraphQLList
2122
import graphql.schema.GraphQLNonNull
@@ -111,9 +112,9 @@ class ValuesResolverTest extends Specification {
111112

112113
when:
113114
def obj = new Person('a', 123)
114-
def resolvedValues = resolver.coerceArgumentValues(schema, [variableDefinition], [variable: obj])
115+
resolver.coerceArgumentValues(schema, [variableDefinition], [variable: obj])
115116
then:
116-
resolvedValues['variable'] == obj
117+
thrown(CoercingParseValueException)
117118
}
118119

119120
def "getVariableValues: simple value gets resolved to a list when the type is a List"() {

0 commit comments

Comments
 (0)