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 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..7601ba9 --- /dev/null +++ b/tests/schemas/repeatable.graphql @@ -0,0 +1 @@ +directive @filter(expression: String!) repeatable on FIELD