Skip to content

Commit d38eec8

Browse files
committed
add variable definition tests; add arguments parsing;
1 parent 45e2acd commit d38eec8

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/parser.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,19 @@ make_parser!(
276276
OperationTypeParser::new()
277277
.and(optional(NameParser::new()))
278278
.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 {
281282
Some(ds) => ds,
282283
None => Vec::new()
283284
};
284285

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)
286292
})
287293
.skip(many::<Vec<_>,_>(or(WhiteSpace::new(), LineTerminator::new(&true))))
288294
.parse_lazy(input)
@@ -797,7 +803,7 @@ mod tests {
797803
}
798804

799805
#[test]
800-
fn test_parse_operation() {
806+
fn test_parse_operation_name() {
801807
// named operation
802808
{
803809
let result = Operation::new(OperationType::Mutation,
@@ -814,6 +820,20 @@ mod tests {
814820
}
815821
}
816822

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+
817837
#[test]
818838
fn test_parse_type() {
819839
assert_successful_parse!(TypeParser, "User", Type::Named(String::from("User")));

0 commit comments

Comments
 (0)