1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::{
directive::DirectiveDef, enum_::EnumTypeDef, fragment::FragmentDef,
input_object::InputObjectTypeDef, interface::InterfaceTypeDef, object::ObjectTypeDef,
operation::OperationDef, scalar::ScalarTypeDef, schema::SchemaDef, union::UnionTypeDef,
};
#[derive(Debug)]
pub struct Document {
pub(crate) operation_definitions: Vec<OperationDef>,
pub(crate) fragment_definitions: Vec<FragmentDef>,
pub(crate) schema_definitions: Vec<SchemaDef>,
pub(crate) scalar_type_definitions: Vec<ScalarTypeDef>,
pub(crate) object_type_definitions: Vec<ObjectTypeDef>,
pub(crate) interface_type_definitions: Vec<InterfaceTypeDef>,
pub(crate) union_type_definitions: Vec<UnionTypeDef>,
pub(crate) enum_type_definitions: Vec<EnumTypeDef>,
pub(crate) input_object_type_definitions: Vec<InputObjectTypeDef>,
pub(crate) directive_definitions: Vec<DirectiveDef>,
}
impl From<Document> for apollo_encoder::Document {
fn from(doc: Document) -> Self {
let mut new_doc = Self::new();
doc.fragment_definitions
.into_iter()
.for_each(|fragment_def| new_doc.fragment(fragment_def.into()));
doc.scalar_type_definitions
.into_iter()
.for_each(|scalar_type_def| new_doc.scalar(scalar_type_def.into()));
doc.schema_definitions
.into_iter()
.for_each(|schema_def| new_doc.schema(schema_def.into()));
doc.object_type_definitions
.into_iter()
.for_each(|object_type_def| new_doc.object(object_type_def.into()));
doc.union_type_definitions
.into_iter()
.for_each(|union_type_def| new_doc.union(union_type_def.into()));
doc.input_object_type_definitions
.into_iter()
.for_each(|input_object_type_def| new_doc.input_object_(input_object_type_def.into()));
doc.interface_type_definitions
.into_iter()
.for_each(|interface_type_def| new_doc.interface(interface_type_def.into()));
doc.enum_type_definitions
.into_iter()
.for_each(|enum_type_def| new_doc.enum_(enum_type_def.into()));
doc.directive_definitions
.into_iter()
.for_each(|directive_def| new_doc.directive(directive_def.into()));
doc.operation_definitions
.into_iter()
.for_each(|operation_def| new_doc.operation(operation_def.into()));
new_doc
}
}
impl From<Document> for String {
fn from(doc: Document) -> Self {
apollo_encoder::Document::from(doc).to_string()
}
}