@@ -36,21 +36,18 @@ fn unsupported_type(
3636 ) )
3737}
3838
39- //for bigint
40- /*
41- */
42- pub ( crate ) fn validate_values2 (
39+ pub ( crate ) fn validate_values (
4340 db : & dyn ValidationDatabase ,
4441 ty : & Node < ast:: Type > ,
4542 argument : & Node < ast:: Argument > ,
4643 var_defs : & [ Node < ast:: VariableDefinition > ] ,
4744) -> Vec < ApolloDiagnostic > {
4845 let mut diagnostics = vec ! [ ] ;
49- value_of_correct_type2 ( db, ty, & argument. value , var_defs, & mut diagnostics) ;
46+ value_of_correct_type ( db, ty, & argument. value , var_defs, & mut diagnostics) ;
5047 diagnostics
5148}
5249
53- pub ( crate ) fn value_of_correct_type2 (
50+ pub ( crate ) fn value_of_correct_type (
5451 db : & dyn ValidationDatabase ,
5552 ty : & Node < ast:: Type > ,
5653 arg_value : & Node < ast:: Value > ,
@@ -72,8 +69,10 @@ pub(crate) fn value_of_correct_type2(
7269 // When expected as an input type, any string (such as "4") or
7370 // integer (such as 4 or -4) input value should be coerced to ID
7471 ast:: Value :: Int ( int) => match & type_definition {
72+ // Any value is valid for a custom scalar.
7573 schema:: ExtendedType :: Scalar ( scalar) if !scalar. is_built_in ( ) => { }
76- schema:: ExtendedType :: Scalar ( _) => match ty. inner_named_type ( ) . as_str ( ) {
74+ schema:: ExtendedType :: Scalar ( scalar) => match scalar. name . as_str ( ) {
75+ // Any integer sequence is valid for an ID.
7776 "ID" => { }
7877 "Int" => {
7978 if int. try_to_i32 ( ) . is_err ( ) {
@@ -118,8 +117,9 @@ pub(crate) fn value_of_correct_type2(
118117 // with numeric content, must raise a request error indicating an
119118 // incorrect type.
120119 ast:: Value :: Float ( float) => match & type_definition {
120+ // Any value is valid for a custom scalar.
121121 schema:: ExtendedType :: Scalar ( scalar) if !scalar. is_built_in ( ) => { }
122- schema:: ExtendedType :: Scalar ( _ ) if ty . inner_named_type ( ) == "Float" => {
122+ schema:: ExtendedType :: Scalar ( scalar ) if scalar . name == "Float" => {
123123 if float. try_to_f64 ( ) . is_err ( ) {
124124 diagnostics. push (
125125 ApolloDiagnostic :: new (
@@ -149,9 +149,7 @@ pub(crate) fn value_of_correct_type2(
149149 // booleans.
150150 // string, ids and custom scalars are ok, and
151151 // don't need a diagnostic.
152- if scalar. is_built_in ( )
153- && !matches ! ( ty. inner_named_type( ) . as_str( ) , "String" | "ID" )
154- {
152+ if scalar. is_built_in ( ) && !matches ! ( scalar. name. as_str( ) , "String" | "ID" ) {
155153 diagnostics. push ( unsupported_type ( db, arg_value, ty) ) ;
156154 }
157155 }
@@ -162,17 +160,14 @@ pub(crate) fn value_of_correct_type2(
162160 // indicating an incorrect type.
163161 ast:: Value :: Boolean ( _) => match & type_definition {
164162 schema:: ExtendedType :: Scalar ( scalar) => {
165- if scalar. is_built_in ( ) && ty . inner_named_type ( ) . as_str ( ) != "Boolean" {
163+ if scalar. is_built_in ( ) && scalar . name . as_str ( ) != "Boolean" {
166164 diagnostics. push ( unsupported_type ( db, arg_value, ty) ) ;
167165 }
168166 }
169167 _ => diagnostics. push ( unsupported_type ( db, arg_value, ty) ) ,
170168 } ,
171169 ast:: Value :: Null => {
172- if !matches ! (
173- type_definition,
174- schema:: ExtendedType :: Enum ( _) | schema:: ExtendedType :: Scalar ( _)
175- ) {
170+ if ty. is_non_null ( ) {
176171 diagnostics. push ( unsupported_type ( db, arg_value, ty) ) ;
177172 }
178173 }
@@ -191,7 +186,7 @@ pub(crate) fn value_of_correct_type2(
191186 if var_def. ty . is_non_null ( ) && default_value. is_null ( ) {
192187 diagnostics. push ( unsupported_type ( db, default_value, & var_def. ty ) )
193188 } else {
194- value_of_correct_type2 (
189+ value_of_correct_type (
195190 db,
196191 & var_def. ty ,
197192 default_value,
@@ -204,9 +199,6 @@ pub(crate) fn value_of_correct_type2(
204199 }
205200 _ => diagnostics. push ( unsupported_type ( db, arg_value, ty) ) ,
206201 } ,
207- // GraphQL has a constant literal to represent enum input values.
208- // GraphQL string literals must not be accepted as an enum input and
209- // instead raise a request error.
210202 ast:: Value :: Enum ( value) => match & type_definition {
211203 schema:: ExtendedType :: Enum ( enum_) => {
212204 if !enum_. values . contains_key ( value) {
@@ -216,12 +208,12 @@ pub(crate) fn value_of_correct_type2(
216208 value. location ( ) ,
217209 DiagnosticData :: UndefinedValue {
218210 value : value. to_string ( ) ,
219- definition : ty . inner_named_type ( ) . to_string ( ) ,
211+ definition : enum_ . name . to_string ( ) ,
220212 } ,
221213 )
222214 . label ( Label :: new (
223215 arg_value. location ( ) ,
224- format ! ( "does not exist on `{}` type" , ty . inner_named_type ( ) ) ,
216+ format ! ( "does not exist on `{}` type" , enum_ . name ) ,
225217 ) ) ,
226218 ) ;
227219 }
@@ -236,14 +228,23 @@ pub(crate) fn value_of_correct_type2(
236228 // of size one, where the single item value is the result of input
237229 // coercion for the list’s item type on the provided value (note
238230 // this may apply recursively for nested lists).
239- ast:: Value :: List ( li) => match & type_definition {
240- schema:: ExtendedType :: Scalar ( _)
241- | schema:: ExtendedType :: Enum ( _)
242- | schema:: ExtendedType :: InputObject ( _) => li
243- . iter ( )
244- . for_each ( |v| value_of_correct_type2 ( db, ty, v, var_defs, diagnostics) ) ,
245- _ => diagnostics. push ( unsupported_type ( db, arg_value, ty) ) ,
246- } ,
231+ ast:: Value :: List ( li) => {
232+ let accepts_list = ty. is_list ( )
233+ // A named type can still accept a list if it is a custom scalar.
234+ || matches ! ( type_definition, schema:: ExtendedType :: Scalar ( scalar) if !scalar. is_built_in( ) ) ;
235+ if !accepts_list {
236+ diagnostics. push ( unsupported_type ( db, arg_value, ty) )
237+ } else {
238+ let item_type = ty. same_location ( ty. item_type ( ) . clone ( ) ) ;
239+ if type_definition. is_input_type ( ) {
240+ for v in li {
241+ value_of_correct_type ( db, & item_type, v, var_defs, diagnostics) ;
242+ }
243+ } else {
244+ diagnostics. push ( unsupported_type ( db, arg_value, & item_type) ) ;
245+ }
246+ }
247+ }
247248 ast:: Value :: Object ( obj) => match & type_definition {
248249 schema:: ExtendedType :: Scalar ( scalar) if !scalar. is_built_in ( ) => ( ) ,
249250 schema:: ExtendedType :: InputObject ( input_obj) => {
@@ -260,12 +261,12 @@ pub(crate) fn value_of_correct_type2(
260261 value. location ( ) ,
261262 DiagnosticData :: UndefinedValue {
262263 value : name. to_string ( ) ,
263- definition : ty . inner_named_type ( ) . to_string ( ) ,
264+ definition : input_obj . name . to_string ( ) ,
264265 } ,
265266 )
266267 . label ( Label :: new (
267268 value. location ( ) ,
268- format ! ( "does not exist on `{}` type" , ty . inner_named_type ( ) ) ,
269+ format ! ( "does not exist on `{}` type" , input_obj . name ) ,
269270 ) ) ,
270271 ) ;
271272 }
@@ -302,7 +303,7 @@ pub(crate) fn value_of_correct_type2(
302303 let used_val = obj. iter ( ) . find ( |( obj_name, ..) | obj_name == input_name) ;
303304
304305 if let Some ( ( _, v) ) = used_val {
305- value_of_correct_type2 ( db, ty, v, var_defs, diagnostics) ;
306+ value_of_correct_type ( db, ty, v, var_defs, diagnostics) ;
306307 }
307308 } )
308309 }
0 commit comments