|
10 | 10 | import graphql.language.Value; |
11 | 11 | import graphql.language.VariableDefinition; |
12 | 12 | import graphql.language.VariableReference; |
| 13 | +import graphql.schema.CoercingParseValueException; |
13 | 14 | import graphql.schema.GraphQLArgument; |
14 | 15 | import graphql.schema.GraphQLEnumType; |
15 | 16 | import graphql.schema.GraphQLInputObjectField; |
@@ -145,19 +146,23 @@ private Object coerceValue(VariableDefinition variableDefinition, GraphQLType gr |
145 | 146 | return returnValue; |
146 | 147 | } |
147 | 148 |
|
148 | | - if (value == null) return null; |
| 149 | + if (value == null) { |
| 150 | + return null; |
| 151 | + } |
149 | 152 |
|
150 | 153 | if (graphQLType instanceof GraphQLScalarType) { |
151 | 154 | return coerceValueForScalar((GraphQLScalarType) graphQLType, value); |
152 | 155 | } else if (graphQLType instanceof GraphQLEnumType) { |
153 | 156 | return coerceValueForEnum((GraphQLEnumType) graphQLType, value); |
154 | 157 | } else if (graphQLType instanceof GraphQLList) { |
155 | 158 | 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); |
159 | 159 | } 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 | + } |
161 | 166 | } else { |
162 | 167 | return assertShouldNeverHappen("unhandled type " + graphQLType); |
163 | 168 | } |
|
0 commit comments