1717import graphql .schema .GraphQLInputObjectField ;
1818import graphql .schema .GraphQLInputObjectType ;
1919import graphql .schema .GraphQLList ;
20- import graphql .schema .GraphQLNonNull ;
2120import graphql .schema .GraphQLScalarType ;
2221import graphql .schema .GraphQLSchema ;
2322import graphql .schema .GraphQLType ;
3130import java .util .stream .Collectors ;
3231
3332import static graphql .Assert .assertShouldNeverHappen ;
33+ import static graphql .schema .GraphQLTypeUtil .isList ;
34+ import static graphql .schema .GraphQLTypeUtil .isNonNull ;
35+ import static graphql .schema .GraphQLTypeUtil .unwrapOne ;
3436import static graphql .schema .visibility .DefaultGraphqlFieldVisibility .DEFAULT_FIELD_VISIBILITY ;
3537
3638@ Internal
@@ -78,7 +80,7 @@ public Map<String, Object> coerceArgumentValues(GraphQLSchema schema, List<Varia
7880 // 3.e.i
7981 Object coercedValue = coerceValueAst (fieldVisibility , variableType , variableDefinition .getDefaultValue (), null );
8082 coercedValues .put (variableName , coercedValue );
81- } else if (isNonNullType (variableType )) {
83+ } else if (isNonNull (variableType )) {
8284 // 3.e.ii
8385 throw new NonNullableValueCoercedAsNullException (variableDefinition , variableType );
8486 }
@@ -103,10 +105,6 @@ private Object getVariableValue(GraphqlFieldVisibility fieldVisibility, Variable
103105 return coerceValue (fieldVisibility , variableDefinition , variableDefinition .getName (), variableType , value );
104106 }
105107
106- private boolean isNonNullType (GraphQLType variableType ) {
107- return variableType instanceof GraphQLNonNull ;
108- }
109-
110108 public Map <String , Object > getArgumentValues (List <GraphQLArgument > argumentTypes , List <Argument > arguments , Map <String , Object > variables ) {
111109 return getArgumentValues (DEFAULT_FIELD_VISIBILITY , argumentTypes , arguments , variables );
112110 }
@@ -149,9 +147,9 @@ private Map<String, Argument> argumentMap(List<Argument> arguments) {
149147 @ SuppressWarnings ("unchecked" )
150148 private Object coerceValue (GraphqlFieldVisibility fieldVisibility , VariableDefinition variableDefinition , String inputName , GraphQLType graphQLType , Object value ) {
151149 try {
152- if (graphQLType instanceof GraphQLNonNull ) {
150+ if (isNonNull ( graphQLType ) ) {
153151 Object returnValue =
154- coerceValue (fieldVisibility , variableDefinition , inputName , (( GraphQLNonNull ) graphQLType ). getWrappedType ( ), value );
152+ coerceValue (fieldVisibility , variableDefinition , inputName , unwrapOne ( graphQLType ), value );
155153 if (returnValue == null ) {
156154 throw new NonNullableValueCoercedAsNullException (variableDefinition , graphQLType );
157155 }
@@ -173,22 +171,22 @@ private Object coerceValue(GraphqlFieldVisibility fieldVisibility, VariableDefin
173171 return coerceValueForInputObjectType (fieldVisibility , variableDefinition , (GraphQLInputObjectType ) graphQLType , (Map <String , Object >) value );
174172 } else {
175173 throw new CoercingParseValueException (
176- "Expected type 'Map' but was '" + value .getClass ().getSimpleName () +
177- "'. Variables for input objects must be an instance of type 'Map'."
174+ "Expected type 'Map' but was '" + value .getClass ().getSimpleName () +
175+ "'. Variables for input objects must be an instance of type 'Map'."
178176 );
179177 }
180178 } else {
181179 return assertShouldNeverHappen ("unhandled type %s" , graphQLType );
182180 }
183181 } catch (CoercingParseValueException e ) {
184182 if (e .getLocations () != null ) {
185- throw e ;
183+ throw e ;
186184 }
187185
188186 throw new CoercingParseValueException (
189- "Variable '" + inputName + "' has an invalid value. " + e .getMessage (),
190- e .getCause (),
191- variableDefinition .getSourceLocation ()
187+ "Variable '" + inputName + "' has an invalid value. " + e .getMessage (),
188+ e .getCause (),
189+ variableDefinition .getSourceLocation ()
192190 );
193191 }
194192 }
@@ -205,19 +203,19 @@ private Object coerceValueForInputObjectType(GraphqlFieldVisibility fieldVisibil
205203
206204 for (GraphQLInputObjectField inputField : fields ) {
207205 if (input .containsKey (inputField .getName ()) || alwaysHasValue (inputField )) {
208- Object value = coerceValue (fieldVisibility , variableDefinition ,
209- inputField .getName (),
210- inputField .getType (),
211- input .get (inputField .getName ()));
212- result .put (inputField .getName (), value == null ? inputField .getDefaultValue () : value );
206+ Object value = coerceValue (fieldVisibility , variableDefinition ,
207+ inputField .getName (),
208+ inputField .getType (),
209+ input .get (inputField .getName ()));
210+ result .put (inputField .getName (), value == null ? inputField .getDefaultValue () : value );
213211 }
214212 }
215213 return result ;
216214 }
217215
218216 private boolean alwaysHasValue (GraphQLInputObjectField inputField ) {
219217 return inputField .getDefaultValue () != null
220- || inputField .getType () instanceof GraphQLNonNull ;
218+ || isNonNull ( inputField .getType ()) ;
221219 }
222220
223221 private Object coerceValueForScalar (GraphQLScalarType graphQLScalarType , Object value ) {
@@ -250,16 +248,16 @@ private Object coerceValueAst(GraphqlFieldVisibility fieldVisibility, GraphQLTyp
250248 if (type instanceof GraphQLScalarType ) {
251249 return parseLiteral (inputValue , ((GraphQLScalarType ) type ).getCoercing ());
252250 }
253- if (type instanceof GraphQLNonNull ) {
254- return coerceValueAst (fieldVisibility , (( GraphQLNonNull ) type ). getWrappedType ( ), inputValue , variables );
251+ if (isNonNull ( type ) ) {
252+ return coerceValueAst (fieldVisibility , unwrapOne ( type ), inputValue , variables );
255253 }
256254 if (type instanceof GraphQLInputObjectType ) {
257255 return coerceValueAstForInputObject (fieldVisibility , (GraphQLInputObjectType ) type , (ObjectValue ) inputValue , variables );
258256 }
259257 if (type instanceof GraphQLEnumType ) {
260258 return parseLiteral (inputValue , ((GraphQLEnumType ) type ).getCoercing ());
261259 }
262- if (type instanceof GraphQLList ) {
260+ if (isList ( type ) ) {
263261 return coerceValueAstForList (fieldVisibility , (GraphQLList ) type , inputValue , variables );
264262 }
265263 return null ;
@@ -328,7 +326,7 @@ private Object coerceValueAstForInputObject(GraphqlFieldVisibility fieldVisibili
328326 }
329327
330328 private void assertNonNullInputField (GraphQLInputObjectField inputTypeField ) {
331- if (inputTypeField .getType () instanceof GraphQLNonNull ) {
329+ if (isNonNull ( inputTypeField .getType ()) ) {
332330 throw new NonNullableValueCoercedAsNullException (inputTypeField );
333331 }
334332 }
0 commit comments