@@ -276,13 +276,19 @@ make_parser!(
276
276
OperationTypeParser :: new( )
277
277
. and( optional( NameParser :: new( ) ) )
278
278
. and( optional( VariableDefinitions :: new( ) ) )
279
- . map( |( ( op_type, name) , defns) | {
280
- let variable_definitions = match defns {
279
+ . and( optional( Directives :: new( ) ) )
280
+ . map( |( ( ( op_type, name) , opt_variable_definitions) , opt_directives) | {
281
+ let variable_definitions = match opt_variable_definitions {
281
282
Some ( ds) => ds,
282
283
None => Vec :: new( )
283
284
} ;
284
285
285
- Operation :: new( op_type, name, variable_definitions, Vec :: new( ) )
286
+ let directives = match opt_directives {
287
+ Some ( ds) => ds,
288
+ None => Vec :: new( ) ,
289
+ } ;
290
+
291
+ Operation :: new( op_type, name, variable_definitions, directives)
286
292
} )
287
293
. skip( many:: <Vec <_>, _>( or( WhiteSpace :: new( ) , LineTerminator :: new( & true ) ) ) )
288
294
. parse_lazy( input)
@@ -797,7 +803,7 @@ mod tests {
797
803
}
798
804
799
805
#[ test]
800
- fn test_parse_operation ( ) {
806
+ fn test_parse_operation_name ( ) {
801
807
// named operation
802
808
{
803
809
let result = Operation :: new ( OperationType :: Mutation ,
@@ -814,6 +820,20 @@ mod tests {
814
820
}
815
821
}
816
822
823
+ #[ test]
824
+ fn test_parse_operation_variables ( ) {
825
+ // operation with variable definitions
826
+ {
827
+ let result = Operation :: new ( OperationType :: Query ,
828
+ Some ( String :: from ( "likeStory" ) ) ,
829
+ vec ! [ VariableDefinition :: new( String :: from( "storyID" ) ,
830
+ Type :: Named ( String :: from( "Int" ) ) ,
831
+ None ) ] ,
832
+ Vec :: new ( ) ) ;
833
+ assert_successful_parse ! ( OperationDefinition , "query likeStory($storyID: Int)" , result) ;
834
+ }
835
+ }
836
+
817
837
#[ test]
818
838
fn test_parse_type ( ) {
819
839
assert_successful_parse ! ( TypeParser , "User" , Type :: Named ( String :: from( "User" ) ) ) ;
0 commit comments