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