From 84ecfb89034a3a197d817c896412578f3ef75373 Mon Sep 17 00:00:00 2001 From: Bojan Serafimov Date: Thu, 3 Sep 2020 12:17:53 -0400 Subject: [PATCH 1/4] Add test --- tests/schema_roundtrips.rs | 1 + tests/schemas/repeatable.graphql | 1 + 2 files changed, 2 insertions(+) create mode 100644 tests/schemas/repeatable.graphql diff --git a/tests/schema_roundtrips.rs b/tests/schema_roundtrips.rs index ab84017..0b1c069 100644 --- a/tests/schema_roundtrips.rs +++ b/tests/schema_roundtrips.rs @@ -49,3 +49,4 @@ fn roundtrip2(filename: &str) { #[test] fn directive() { roundtrip("directive"); } #[test] fn kitchen_sink() { roundtrip2("kitchen-sink"); } #[test] fn directive_descriptions() { roundtrip2("directive_descriptions"); } +#[test] fn repeatable() {roundtrip("repeatable")} diff --git a/tests/schemas/repeatable.graphql b/tests/schemas/repeatable.graphql new file mode 100644 index 0000000..052ec1d --- /dev/null +++ b/tests/schemas/repeatable.graphql @@ -0,0 +1 @@ +directive @filter(expression: String!) repeatable on FIELD \ No newline at end of file From c6e3bd9cf84fdafa50eba5d18775d3df98ba188e Mon Sep 17 00:00:00 2001 From: Bojan Serafimov Date: Thu, 3 Sep 2020 12:18:50 -0400 Subject: [PATCH 2/4] Add newline --- tests/schemas/repeatable.graphql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/schemas/repeatable.graphql b/tests/schemas/repeatable.graphql index 052ec1d..7601ba9 100644 --- a/tests/schemas/repeatable.graphql +++ b/tests/schemas/repeatable.graphql @@ -1 +1 @@ -directive @filter(expression: String!) repeatable on FIELD \ No newline at end of file +directive @filter(expression: String!) repeatable on FIELD From 7bbb89c54de9f1184e252b4d62e1106acaf1749c Mon Sep 17 00:00:00 2001 From: Bojan Serafimov Date: Thu, 3 Sep 2020 12:49:02 -0400 Subject: [PATCH 3/4] Implement repeatable --- src/schema/ast.rs | 2 ++ src/schema/format.rs | 3 +++ src/schema/grammar.rs | 4 +++- tests/schema_roundtrips.rs | 9 ++++++++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/schema/ast.rs b/src/schema/ast.rs index 824703b..39ba829 100644 --- a/src/schema/ast.rs +++ b/src/schema/ast.rs @@ -405,6 +405,7 @@ pub struct DirectiveDefinition<'a, T: Text<'a>> { pub description: Option, pub name: T::Value, pub arguments: Vec>, + pub repeatable: bool, pub locations: Vec, } @@ -417,6 +418,7 @@ where T: Text<'a> description: None, name, arguments: vec![], + repeatable: false, locations: vec![], } } diff --git a/src/schema/format.rs b/src/schema/format.rs index 2fcfd84..cd1841c 100644 --- a/src/schema/format.rs +++ b/src/schema/format.rs @@ -421,6 +421,9 @@ impl<'a, T> Displayable for DirectiveDefinition<'a, T> f.write("directive @"); f.write(self.name.as_ref()); format_arguments(&self.arguments, f); + if self.repeatable { + f.write(" repeatable"); + } if !self.locations.is_empty() { f.write(" on "); let mut first = true; diff --git a/src/schema/grammar.rs b/src/schema/grammar.rs index 4dc4788..a8f0113 100644 --- a/src/schema/grammar.rs +++ b/src/schema/grammar.rs @@ -474,11 +474,13 @@ pub fn directive_definition<'a, T>(input: &mut TokenStream<'a>) position(), ident("directive").and(punct("@")).with(name::<'a, T>()), parser(arguments_definition), + optional(ident("repeatable")), ident("on").with(parser(directive_locations)), ) - .map(|(position, name, arguments, locations)| { + .map(|(position, name, arguments, repeatable, locations)| { DirectiveDefinition { position, name, arguments, locations, + repeatable: repeatable.is_some(), description: None, // is filled in described_definition } }) diff --git a/tests/schema_roundtrips.rs b/tests/schema_roundtrips.rs index 0b1c069..3c4edec 100644 --- a/tests/schema_roundtrips.rs +++ b/tests/schema_roundtrips.rs @@ -11,7 +11,14 @@ fn roundtrip(filename: &str) { let path = format!("tests/schemas/{}.graphql", filename); let mut f = File::open(&path).unwrap(); f.read_to_string(&mut buf).unwrap(); - let ast = parse_schema::(&buf).unwrap().to_owned(); + let ast = match parse_schema::(&buf) { + Ok(ast) => ast, + Err(err) => { + println!("{:?}", err); + panic!() + } + }; + // let ast = parse_schema::(&buf).unwrap().to_owned(); assert_eq!(ast.to_string(), buf); } From f9148456237b13be10d49992c0a54147246eb18a Mon Sep 17 00:00:00 2001 From: Bojan Serafimov Date: Thu, 3 Sep 2020 12:51:20 -0400 Subject: [PATCH 4/4] Revert unrelated change --- tests/schema_roundtrips.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/tests/schema_roundtrips.rs b/tests/schema_roundtrips.rs index 3c4edec..0b1c069 100644 --- a/tests/schema_roundtrips.rs +++ b/tests/schema_roundtrips.rs @@ -11,14 +11,7 @@ fn roundtrip(filename: &str) { let path = format!("tests/schemas/{}.graphql", filename); let mut f = File::open(&path).unwrap(); f.read_to_string(&mut buf).unwrap(); - let ast = match parse_schema::(&buf) { - Ok(ast) => ast, - Err(err) => { - println!("{:?}", err); - panic!() - } - }; - // let ast = parse_schema::(&buf).unwrap().to_owned(); + let ast = parse_schema::(&buf).unwrap().to_owned(); assert_eq!(ast.to_string(), buf); }