@@ -57,11 +57,25 @@ pub struct FieldSelection<'query, 'schema> {
5757
5858 pub schema_field : OutputField < ' schema > ,
5959
60- pub arguments : Vec < ( & ' schema str , TypedValue < ' query , ' schema > ) > ,
60+ pub arguments : Vec < Argument < ' query , ' schema > > ,
61+
62+ pub directives : Vec < Directive < ' query , ' schema > > ,
6163
6264 pub field : Field < ' query , ' schema > ,
6365}
6466
67+ #[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
68+ pub struct Argument < ' query , ' schema > {
69+ pub name : & ' schema str ,
70+ pub value : TypedValue < ' query , ' schema > ,
71+ }
72+
73+ #[ derive( Clone , Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
74+ pub struct Directive < ' query , ' schema > {
75+ pub name : & ' schema str ,
76+ pub arguments : Vec < Argument < ' query , ' schema > > ,
77+ }
78+
6579#[ derive( Debug , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
6680pub enum Field < ' query , ' schema > {
6781 /// A composite field contains another selection set.
@@ -94,14 +108,16 @@ impl<'query, 'schema> FieldSelection<'query, 'schema> {
94108 fn new (
95109 name : & ' query str ,
96110 alias : Option < & ' query str > ,
97- arguments : Vec < ( & ' schema str , TypedValue < ' query , ' schema > ) > ,
111+ arguments : Vec < Argument < ' query , ' schema > > ,
112+ directives : Vec < Directive < ' query , ' schema > > ,
98113 schema_field : OutputField < ' schema > ,
99114 field : Field < ' query , ' schema > ,
100115 ) -> FieldSelection < ' query , ' schema > {
101116 FieldSelection {
102117 name,
103118 alias,
104119 arguments,
120+ directives,
105121 schema_field,
106122 field,
107123 }
@@ -278,29 +294,43 @@ impl<'a, 'docs> Normaliser<'a, 'docs> {
278294
279295 let mut arguments = Vec :: new ( ) ;
280296 for argument in field. arguments ( ) {
281- let name = argument. name ( ) ;
282- let value = argument. value ( ) ;
283-
284- let schema_arg = schema_field
285- . arguments
286- . iter ( )
287- . find ( |arg| arg. name == name)
288- . ok_or_else ( || dbg ! ( Error :: UnknownArgument ( name. to_string( ) ) ) ) ?;
289-
290- arguments. push ( (
291- schema_arg. name ,
292- TypedValue :: from_query_value (
293- value,
294- schema_arg. value_type . clone ( ) ,
295- & self . variables ,
296- ) ?,
297- ) ) ;
297+ arguments. push ( self . convert_argument ( & schema_field, argument) ?) ;
298298 }
299299
300+ let directives = field
301+ . directives ( )
302+ . map ( |directive| {
303+ let name = directive. name ( ) ;
304+ let schema_directive = self . type_index . directive ( name) ?;
305+
306+ let mut arguments = Vec :: new ( ) ;
307+ for argument in directive. arguments ( ) {
308+ let name = argument. name ( ) ;
309+ let schema_arg = schema_directive
310+ . arguments ( )
311+ . find ( |arg| arg. name ( ) == name)
312+ . ok_or_else ( || Error :: UnknownArgument ( name. to_string ( ) ) ) ?;
313+
314+ arguments. push ( Argument {
315+ name,
316+ value : TypedValue :: from_query_value (
317+ argument. value ( ) ,
318+ InputFieldType :: from_parser ( schema_arg. ty ( ) , self . type_index ) ,
319+ & self . variables ,
320+ ) ?,
321+ } ) ;
322+ }
323+
324+ dbg ! ( & arguments) ;
325+ Ok ( Directive { name, arguments } )
326+ } )
327+ . collect :: < Result < _ , Error > > ( ) ?;
328+
300329 Ok ( vec ! [ Selection :: Field ( FieldSelection :: new(
301330 field. name( ) ,
302331 field. alias( ) ,
303332 arguments,
333+ directives,
304334 schema_field,
305335 inner_field,
306336 ) ) ] )
@@ -343,6 +373,29 @@ impl<'a, 'docs> Normaliser<'a, 'docs> {
343373 }
344374 }
345375
376+ fn convert_argument (
377+ & self ,
378+ schema_field : & OutputField < ' docs > ,
379+ argument : parser:: Argument < ' docs > ,
380+ ) -> Result < Argument < ' docs , ' docs > , Error > {
381+ let name = argument. name ( ) ;
382+ let value = argument. value ( ) ;
383+ let schema_arg = schema_field
384+ . arguments
385+ . iter ( )
386+ . find ( |arg| arg. name == name)
387+ . ok_or_else ( || dbg ! ( Error :: UnknownArgument ( name. to_string( ) ) ) ) ?;
388+
389+ Ok ( Argument {
390+ name : schema_arg. name ,
391+ value : TypedValue :: from_query_value (
392+ value,
393+ schema_arg. value_type . clone ( ) ,
394+ & self . variables ,
395+ ) ?,
396+ } )
397+ }
398+
346399 fn normalise_abstract_selection_set (
347400 & mut self ,
348401 selection_set : Iter < ' docs , parser:: Selection < ' docs > > ,
@@ -489,7 +542,7 @@ impl<'schema> SelectionSet<'_, 'schema> {
489542 field
490543 . arguments
491544 . iter ( )
492- . map ( |( _ , arg) | arg. value_type ( ) . inner_ref ( ) . clone ( ) )
545+ . map ( |arg| arg. value . value_type ( ) . inner_ref ( ) . clone ( ) )
493546 . collect :: < Vec < _ > > ( )
494547 } )
495548 . collect ( )
0 commit comments