apollo_parser/parser/grammar/
description.rs1use crate::Parser;
2use crate::SyntaxKind;
3
4pub(crate) fn description(p: &mut Parser) {
9 let _g = p.start_node(SyntaxKind::DESCRIPTION);
10 let _g_string = p.start_node(SyntaxKind::STRING_VALUE);
11 p.bump(SyntaxKind::STRING)
12}
13
14#[cfg(test)]
15mod tests {
16 use super::*;
17 use crate::cst;
18 #[test]
19 fn it_can_access_definition_description() {
20 let schema = r#"
21"""
22description for Query object type
23"""
24type Query {
25 bestSellers(category: ProductCategory = ALL): [Product] @join__field(graph: PRODUCTS)
26}
27 "#;
28 let parser = Parser::new(schema);
29 let cst = parser.parse();
30
31 assert!(cst.errors.is_empty());
32
33 let document = cst.document();
34 for definition in document.definitions() {
35 if let cst::Definition::ObjectTypeDefinition(obj_def) = definition {
36 let desc: String = obj_def
37 .description()
38 .unwrap()
39 .string_value()
40 .unwrap()
41 .into();
42 assert_eq!(desc, "description for Query object type");
43 return;
44 }
45 }
46 panic!("object type definition has not been catched");
47 }
48}