Skip to content

Commit

Permalink
fix(apollo-parser): add repeatable kw support in ungrammar (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjjj authored Mar 7, 2022
1 parent d2adc6d commit b18be67
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions crates/apollo-parser/src/ast/generated/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ impl DirectiveDefinition {
pub fn arguments_definition(&self) -> Option<ArgumentsDefinition> {
support::child(&self.syntax)
}
pub fn repeatable_token(&self) -> Option<SyntaxToken> {
support::token(&self.syntax, S![repeatable])
}
pub fn on_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, S![on]) }
pub fn directive_locations(&self) -> Option<DirectiveLocations> { support::child(&self.syntax) }
}
Expand Down
30 changes: 30 additions & 0 deletions crates/apollo-parser/src/parser/grammar/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,33 @@ pub(crate) fn directives(p: &mut Parser) {
directive(p);
}
}

#[cfg(test)]
mod tests {
use crate::ast;

use super::*;

#[test]
fn it_can_access_repeatable_kw_on_directive_definition() {
let schema = r#"
directive @example(isTreat: Boolean, treatKind: String) repeatable on FIELD | MUTATION
"#;
let parser = Parser::new(schema);
let ast = parser.parse();

assert!(ast.errors.is_empty());

let document = ast.document();
for definition in document.definitions() {
if let ast::Definition::DirectiveDefinition(dir_def) = definition {
assert_eq!(
dir_def.repeatable_token().unwrap().kind(),
SyntaxKind::repeatable_KW
);
return;
}
}
panic!("Expected AST to have a Directive Definition");
}
}
2 changes: 1 addition & 1 deletion graphql.ungram
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ InputObjectTypeExtension =
| 'extend' 'input' Name Directives?

DirectiveDefinition =
Description? 'directive' '@' Name ArgumentsDefinition? 'on' DirectiveLocations
Description? 'directive' '@' Name ArgumentsDefinition? 'repeatable'? 'on' DirectiveLocations

// In the spec, DirectiveLocations is defined as an enum of:
// DirectiveLocations
Expand Down

0 comments on commit b18be67

Please sign in to comment.