libgraphql_parser/ast/
schema_extension.rs1use crate::ast::ast_node::append_span_source_slice;
2use crate::ast::AstNode;
3use crate::ast::DelimiterPair;
4use crate::ast::DirectiveAnnotation;
5use crate::ast::RootOperationTypeDefinition;
6use crate::ByteSpan;
7use crate::SourceMap;
8use crate::SourceSpan;
9use crate::token::GraphQLToken;
10use inherent::inherent;
11
12#[derive(Clone, Debug, PartialEq)]
18pub struct SchemaExtension<'src> {
19 pub directives: Vec<DirectiveAnnotation<'src>>,
20 pub root_operations:
21 Vec<RootOperationTypeDefinition<'src>>,
22 pub span: ByteSpan,
23 pub syntax: Option<Box<SchemaExtensionSyntax<'src>>>,
24}
25
26#[derive(Clone, Debug, PartialEq)]
28pub struct SchemaExtensionSyntax<'src> {
29 pub braces: Option<DelimiterPair<'src>>,
30 pub extend_keyword: GraphQLToken<'src>,
31 pub schema_keyword: GraphQLToken<'src>,
32}
33
34#[inherent]
35impl AstNode for SchemaExtension<'_> {
36 pub fn append_source(
38 &self,
39 sink: &mut String,
40 source: Option<&str>,
41 ) {
42 if let Some(src) = source {
43 append_span_source_slice(
44 self.span, sink, src,
45 );
46 }
47 }
48
49 #[inline]
56 pub fn byte_span(&self) -> ByteSpan {
57 self.span
58 }
59
60 #[inline]
67 pub fn source_span(
68 &self,
69 source_map: &SourceMap,
70 ) -> Option<SourceSpan> {
71 self.byte_span().resolve(source_map)
72 }
73}