Skip to content

Commit 2e8ca0c

Browse files
Parse repeatable directive definitions (#37)
1 parent 45167b5 commit 2e8ca0c

File tree

5 files changed

+10
-1
lines changed

5 files changed

+10
-1
lines changed

src/schema/ast.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ pub struct DirectiveDefinition<'a, T: Text<'a>> {
405405
pub description: Option<String>,
406406
pub name: T::Value,
407407
pub arguments: Vec<InputValue<'a, T>>,
408+
pub repeatable: bool,
408409
pub locations: Vec<DirectiveLocation>,
409410
}
410411

@@ -417,6 +418,7 @@ where T: Text<'a>
417418
description: None,
418419
name,
419420
arguments: vec![],
421+
repeatable: false,
420422
locations: vec![],
421423
}
422424
}

src/schema/format.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ impl<'a, T> Displayable for DirectiveDefinition<'a, T>
421421
f.write("directive @");
422422
f.write(self.name.as_ref());
423423
format_arguments(&self.arguments, f);
424+
if self.repeatable {
425+
f.write(" repeatable");
426+
}
424427
if !self.locations.is_empty() {
425428
f.write(" on ");
426429
let mut first = true;

src/schema/grammar.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,11 +474,13 @@ pub fn directive_definition<'a, T>(input: &mut TokenStream<'a>)
474474
position(),
475475
ident("directive").and(punct("@")).with(name::<'a, T>()),
476476
parser(arguments_definition),
477+
optional(ident("repeatable")),
477478
ident("on").with(parser(directive_locations)),
478479
)
479-
.map(|(position, name, arguments, locations)| {
480+
.map(|(position, name, arguments, repeatable, locations)| {
480481
DirectiveDefinition {
481482
position, name, arguments, locations,
483+
repeatable: repeatable.is_some(),
482484
description: None, // is filled in described_definition
483485
}
484486
})

tests/schema_roundtrips.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ fn roundtrip2(filename: &str) {
4949
#[test] fn directive() { roundtrip("directive"); }
5050
#[test] fn kitchen_sink() { roundtrip2("kitchen-sink"); }
5151
#[test] fn directive_descriptions() { roundtrip2("directive_descriptions"); }
52+
#[test] fn repeatable() {roundtrip("repeatable")}

tests/schemas/repeatable.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
directive @filter(expression: String!) repeatable on FIELD

0 commit comments

Comments
 (0)