1#![doc = include_str!("readme.md")]
2use core::range::Range;
3
4type SourceSpan = Range<usize>;
5
6#[derive(Debug, Clone, PartialEq)]
8pub struct GraphQLRoot {
9 pub document: Document,
11}
12
13impl GraphQLRoot {
14 pub fn new(document: Document) -> Self {
16 Self { document }
17 }
18}
19
20#[derive(Debug, Clone, PartialEq)]
22pub struct Document {
23 pub definitions: Vec<Definition>,
25 pub span: SourceSpan,
27}
28
29impl Document {
30 pub fn new(span: SourceSpan) -> Self {
32 Self { definitions: Vec::new(), span }
33 }
34
35 pub fn with_definition(mut self, definition: Definition) -> Self {
37 self.definitions.push(definition);
38 self
39 }
40}
41
42#[derive(Debug, Clone, PartialEq)]
44pub enum Definition {
45 Operation(OperationDefinition),
47 Fragment(FragmentDefinition),
49 Schema(SchemaDefinition),
51 Type(TypeDefinition),
53}
54
55#[derive(Debug, Clone, PartialEq)]
57pub struct OperationDefinition {
58 pub operation_type: OperationType,
60 pub name: Option<String>,
62 pub span: SourceSpan,
64}
65
66impl OperationDefinition {
67 pub fn new(operation_type: OperationType, span: SourceSpan) -> Self {
69 Self { operation_type, name: None, span }
70 }
71
72 pub fn with_name(mut self, name: impl Into<String>) -> Self {
74 self.name = Some(name.into());
75 self
76 }
77}
78
79#[derive(Debug, Clone, PartialEq)]
81pub enum OperationType {
82 Query,
84 Mutation,
86 Subscription,
88}
89
90#[derive(Debug, Clone, PartialEq)]
92pub struct FragmentDefinition {
93 pub name: String,
95 pub span: SourceSpan,
97}
98
99impl FragmentDefinition {
100 pub fn new(name: impl Into<String>, span: SourceSpan) -> Self {
102 Self { name: name.into(), span }
103 }
104}
105
106#[derive(Debug, Clone, PartialEq)]
108pub struct SchemaDefinition {
109 pub span: SourceSpan,
111}
112
113impl SchemaDefinition {
114 pub fn new(span: SourceSpan) -> Self {
116 Self { span }
117 }
118}
119
120#[derive(Debug, Clone, PartialEq)]
122pub struct TypeDefinition {
123 pub name: String,
125 pub span: SourceSpan,
127}
128
129impl TypeDefinition {
130 pub fn new(name: impl Into<String>, span: SourceSpan) -> Self {
132 Self { name: name.into(), span }
133 }
134}