1+ use std:: borrow:: Cow ;
12use std:: collections:: HashMap ;
23
34use graphql_parser:: query:: Value as QueryValue ;
@@ -53,15 +54,16 @@ fn is_deprecated_enum<'exec, 'schema: 'exec>(enum_val: &'exec EnumValue<'schema,
5354
5455fn kind_to_str < ' exec , ' schema : ' exec > (
5556 type_def : & ' exec TypeDefinition < ' schema , String > ,
56- ) -> & ' exec str {
57- match type_def {
57+ ) -> Cow < ' exec , str > {
58+ ( match type_def {
5859 TypeDefinition :: Scalar ( _) => "SCALAR" ,
5960 TypeDefinition :: Object ( _) => "OBJECT" ,
6061 TypeDefinition :: Interface ( _) => "INTERFACE" ,
6162 TypeDefinition :: Union ( _) => "UNION" ,
6263 TypeDefinition :: Enum ( _) => "ENUM" ,
6364 TypeDefinition :: InputObject ( _) => "INPUT_OBJECT" ,
64- }
65+ } )
66+ . into ( )
6567}
6668
6769fn resolve_input_value < ' exec , ' schema : ' exec > (
@@ -83,14 +85,14 @@ fn resolve_input_value_selections<'exec, 'schema: 'exec>(
8385 for item in selection_items {
8486 if let SelectionItem :: Field ( field) = item {
8587 let value = match field. name . as_str ( ) {
86- "name" => Value :: String ( & iv. name ) ,
88+ "name" => Value :: String ( iv. name . as_str ( ) . into ( ) ) ,
8789 "description" => iv
8890 . description
8991 . as_ref ( )
90- . map_or ( Value :: Null , |s| Value :: String ( s) ) ,
92+ . map_or ( Value :: Null , |s| Value :: String ( s. into ( ) ) ) ,
9193 "type" => resolve_type ( & iv. value_type , & field. selections , ctx) ,
9294 "defaultValue" => Value :: Null , // TODO: support default values
93- "__typename" => Value :: String ( "__InputValue" ) ,
95+ "__typename" => Value :: String ( "__InputValue" . into ( ) ) ,
9496 _ => Value :: Null ,
9597 } ;
9698 iv_data. push ( ( field. selection_identifier ( ) , value) ) ;
@@ -124,11 +126,11 @@ fn resolve_field_selections<'exec, 'schema: 'exec>(
124126 for item in selection_items {
125127 if let SelectionItem :: Field ( field) = item {
126128 let value = match field. name . as_str ( ) {
127- "name" => Value :: String ( & f. name ) ,
129+ "name" => Value :: String ( f. name . as_str ( ) . into ( ) ) ,
128130 "description" => f
129131 . description
130132 . as_ref ( )
131- . map_or ( Value :: Null , |s| Value :: String ( s) ) ,
133+ . map_or ( Value :: Null , |s| Value :: String ( s. into ( ) ) ) ,
132134 "args" => {
133135 let args: Vec < _ > = f
134136 . arguments
@@ -139,10 +141,9 @@ fn resolve_field_selections<'exec, 'schema: 'exec>(
139141 }
140142 "type" => resolve_type ( & f. field_type , & field. selections , ctx) ,
141143 "isDeprecated" => Value :: Bool ( is_deprecated ( & f. directives ) ) ,
142- "deprecationReason" => {
143- get_deprecation_reason ( & f. directives ) . map_or ( Value :: Null , Value :: String )
144- }
145- "__typename" => Value :: String ( "__Field" ) ,
144+ "deprecationReason" => get_deprecation_reason ( & f. directives )
145+ . map_or ( Value :: Null , |s| Value :: String ( s. into ( ) ) ) ,
146+ "__typename" => Value :: String ( "__Field" . into ( ) ) ,
146147 _ => Value :: Null ,
147148 } ;
148149 field_data. push ( ( field. selection_identifier ( ) , value) ) ;
@@ -174,16 +175,15 @@ fn resolve_enum_value_selections<'exec, 'schema: 'exec>(
174175 for item in selection_items {
175176 if let SelectionItem :: Field ( field) = item {
176177 let value = match field. name . as_str ( ) {
177- "name" => Value :: String ( & ev. name ) ,
178+ "name" => Value :: String ( ev. name . as_str ( ) . into ( ) ) ,
178179 "description" => ev
179180 . description
180181 . as_ref ( )
181- . map_or ( Value :: Null , |s| Value :: String ( s) ) ,
182+ . map_or ( Value :: Null , |s| Value :: String ( s. into ( ) ) ) ,
182183 "isDeprecated" => Value :: Bool ( is_deprecated_enum ( ev) ) ,
183- "deprecationReason" => {
184- get_deprecation_reason ( & ev. directives ) . map_or ( Value :: Null , Value :: String )
185- }
186- "__typename" => Value :: String ( "__EnumValue" ) ,
184+ "deprecationReason" => get_deprecation_reason ( & ev. directives )
185+ . map_or ( Value :: Null , |s| Value :: String ( s. into ( ) ) ) ,
186+ "__typename" => Value :: String ( "__EnumValue" . into ( ) ) ,
187187 _ => Value :: Null ,
188188 } ;
189189 ev_data. push ( ( field. selection_identifier ( ) , value) ) ;
@@ -227,7 +227,7 @@ fn resolve_type_definition_selections<'exec, 'schema: 'exec>(
227227 TypeDefinition :: Enum ( e) => Some ( & e. name ) ,
228228 TypeDefinition :: InputObject ( io) => Some ( & io. name ) ,
229229 }
230- . map ( |s| Value :: String ( s) )
230+ . map ( |s| Value :: String ( s. into ( ) ) )
231231 . unwrap_or ( Value :: Null ) ,
232232 "description" => match type_def {
233233 TypeDefinition :: Scalar ( s) => s. description . as_ref ( ) ,
@@ -237,7 +237,7 @@ fn resolve_type_definition_selections<'exec, 'schema: 'exec>(
237237 TypeDefinition :: Enum ( e) => e. description . as_ref ( ) ,
238238 TypeDefinition :: InputObject ( io) => io. description . as_ref ( ) ,
239239 }
240- . map_or ( Value :: Null , |s| Value :: String ( s) ) ,
240+ . map_or ( Value :: Null , |s| Value :: String ( s. into ( ) ) ) ,
241241 "fields" => {
242242 let fields = match type_def {
243243 TypeDefinition :: Object ( o) => Some ( & o. fields ) ,
@@ -338,7 +338,7 @@ fn resolve_type_definition_selections<'exec, 'schema: 'exec>(
338338 _ => Value :: Null ,
339339 } ,
340340 "ofType" => Value :: Null ,
341- "__typename" => Value :: String ( "__Type" ) ,
341+ "__typename" => Value :: String ( "__Type" . into ( ) ) ,
342342 _ => Value :: Null ,
343343 } ;
344344 type_data. push ( ( field. selection_identifier ( ) , value) ) ;
@@ -373,10 +373,10 @@ fn resolve_wrapper_type_selections<'exec, 'schema: 'exec>(
373373 for item in selection_items {
374374 if let SelectionItem :: Field ( field) = item {
375375 let value = match field. name . as_str ( ) {
376- "kind" => Value :: String ( kind) ,
376+ "kind" => Value :: String ( kind. into ( ) ) ,
377377 "name" => Value :: Null ,
378378 "ofType" => resolve_type ( inner_type, & field. selections , ctx) ,
379- "__typename" => Value :: String ( "__Type" ) ,
379+ "__typename" => Value :: String ( "__Type" . into ( ) ) ,
380380 _ => Value :: Null ,
381381 } ;
382382 type_data. push ( ( field. selection_identifier ( ) , value) ) ;
@@ -426,16 +426,16 @@ fn resolve_directive_selections<'exec, 'schema: 'exec>(
426426 for item in selection_items {
427427 if let SelectionItem :: Field ( field) = item {
428428 let value = match field. name . as_str ( ) {
429- "name" => Value :: String ( & d. name ) ,
429+ "name" => Value :: String ( d. name . as_str ( ) . into ( ) ) ,
430430 "description" => d
431431 . description
432432 . as_ref ( )
433- . map_or ( Value :: Null , |s| Value :: String ( s) ) ,
433+ . map_or ( Value :: Null , |s| Value :: String ( s. into ( ) ) ) ,
434434 "locations" => {
435435 let locs: Vec < _ > = d
436436 . locations
437437 . iter ( )
438- . map ( |l| Value :: String ( l. as_str ( ) ) )
438+ . map ( |l| Value :: String ( l. as_str ( ) . into ( ) ) )
439439 . collect ( ) ;
440440 Value :: Array ( locs)
441441 }
@@ -448,7 +448,7 @@ fn resolve_directive_selections<'exec, 'schema: 'exec>(
448448 Value :: Array ( args)
449449 }
450450 "isRepeatable" => Value :: Bool ( d. repeatable ) ,
451- "__typename" => Value :: String ( "__Directive" ) ,
451+ "__typename" => Value :: String ( "__Directive" . into ( ) ) ,
452452 _ => Value :: Null ,
453453 } ;
454454 directive_data. push ( ( field. selection_identifier ( ) , value) ) ;
@@ -526,7 +526,7 @@ fn resolve_schema_selections<'exec, 'schema: 'exec>(
526526 . collect ( ) ;
527527 Value :: Array ( directives)
528528 }
529- "__typename" => Value :: String ( "__Schema" ) ,
529+ "__typename" => Value :: String ( "__Schema" . into ( ) ) ,
530530 _ => Value :: Null ,
531531 } ;
532532 schema_data. push ( ( inner_field. selection_identifier ( ) , value) ) ;
@@ -590,7 +590,7 @@ fn resolve_root_introspection_selections<'exec, 'schema: 'exec>(
590590 Value :: Null
591591 }
592592 }
593- "__typename" => Value :: String ( root_type_name) ,
593+ "__typename" => Value :: String ( root_type_name. into ( ) ) ,
594594 _ => Value :: Null ,
595595 } ;
596596 data. push ( ( field. selection_identifier ( ) , value) ) ;
0 commit comments