cynic_parser/executable/generated/
operation.rs1use super::prelude::*;
2use super::{
3 ExecutableId,
4 descriptions::Description,
5 directive::Directive,
6 ids::{DescriptionId, DirectiveId, OperationDefinitionId, SelectionId, VariableDefinitionId},
7 selections::Selection,
8 variable::VariableDefinition,
9};
10#[allow(unused_imports)]
11use std::fmt::{self, Write};
12
13pub struct OperationDefinitionRecord {
14 pub description: Option<DescriptionId>,
15 pub operation_type: OperationType,
16 pub operation_type_span: Option<Span>,
17 pub name: Option<StringId>,
18 pub name_span: Option<Span>,
19 pub variable_definitions: IdRange<VariableDefinitionId>,
20 pub directives: IdRange<DirectiveId>,
21 pub selection_set: IdRange<SelectionId>,
22 pub selection_set_span: Span,
23}
24
25#[derive(Clone, Copy)]
26pub struct OperationDefinition<'a>(pub(in super::super) ReadContext<'a, OperationDefinitionId>);
27
28impl<'a> OperationDefinition<'a> {
29 pub fn description(&self) -> Option<Description<'a>> {
30 let document = self.0.document;
31 document
32 .lookup(self.0.id)
33 .description
34 .map(|id| document.read(id))
35 }
36 pub fn operation_type(&self) -> OperationType {
37 let document = self.0.document;
38 document.lookup(self.0.id).operation_type
39 }
40 pub fn operation_type_span(&self) -> Option<Span> {
41 let document = self.0.document;
42 document.lookup(self.0.id).operation_type_span
43 }
44 pub fn name(&self) -> Option<&'a str> {
45 let document = self.0.document;
46 document
47 .lookup(self.0.id)
48 .name
49 .map(|id| document.lookup(id))
50 }
51 pub fn name_span(&self) -> Option<Span> {
52 let document = self.0.document;
53 document.lookup(self.0.id).name_span
54 }
55 pub fn variable_definitions(&self) -> Iter<'a, VariableDefinition<'a>> {
56 let document = self.0.document;
57 super::Iter::new(document.lookup(self.0.id).variable_definitions, document)
58 }
59 pub fn directives(&self) -> Iter<'a, Directive<'a>> {
60 let document = self.0.document;
61 super::Iter::new(document.lookup(self.0.id).directives, document)
62 }
63 pub fn selection_set(&self) -> Iter<'a, Selection<'a>> {
64 let document = self.0.document;
65 super::Iter::new(document.lookup(self.0.id).selection_set, document)
66 }
67 pub fn selection_set_span(&self) -> Span {
68 let document = self.0.document;
69 document.lookup(self.0.id).selection_set_span
70 }
71}
72
73impl OperationDefinition<'_> {
74 pub fn id(&self) -> OperationDefinitionId {
75 self.0.id
76 }
77}
78
79impl fmt::Debug for OperationDefinition<'_> {
80 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81 f.debug_struct("OperationDefinition")
82 .field("description", &self.description())
83 .field("operation_type", &self.operation_type())
84 .field("name", &self.name())
85 .field("variable_definitions", &self.variable_definitions())
86 .field("directives", &self.directives())
87 .field("selection_set", &self.selection_set())
88 .finish()
89 }
90}
91
92impl ExecutableId for OperationDefinitionId {
93 type Reader<'a> = OperationDefinition<'a>;
94 fn read(self, document: &ExecutableDocument) -> Self::Reader<'_> {
95 OperationDefinition(ReadContext { id: self, document })
96 }
97}
98
99impl IdReader for OperationDefinition<'_> {
100 type Id = OperationDefinitionId;
101 type Reader<'a> = OperationDefinition<'a>;
102 fn new(id: Self::Id, document: &'_ ExecutableDocument) -> Self::Reader<'_> {
103 document.read(id)
104 }
105}