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
use arbitrary::Result;
use crate::{
description::Description, directive::Directive, input_value::InputValueDef, name::Name,
DocumentBuilder,
};
#[derive(Debug, Clone)]
pub struct InputObjectTypeDef {
pub(crate) name: Name,
pub(crate) description: Option<Description>,
pub(crate) fields: Vec<InputValueDef>,
pub(crate) directives: Vec<Directive>,
pub(crate) extend: bool,
}
impl From<InputObjectTypeDef> for apollo_encoder::InputObjectDefinition {
fn from(input_object_def: InputObjectTypeDef) -> Self {
let mut new_input_object_def = Self::new(input_object_def.name.into());
new_input_object_def.description(input_object_def.description.map(String::from));
if input_object_def.extend {
new_input_object_def.extend();
}
input_object_def
.directives
.into_iter()
.for_each(|directive| new_input_object_def.directive(directive.into()));
input_object_def
.fields
.into_iter()
.for_each(|field| new_input_object_def.field(field.into()));
new_input_object_def
}
}
impl<'a> DocumentBuilder<'a> {
pub fn input_object_type_definition(&mut self) -> Result<InputObjectTypeDef> {
let description = self
.u
.arbitrary()
.unwrap_or(false)
.then(|| self.description())
.transpose()?;
let name = self.type_name()?;
let fields = self.input_values_def()?;
Ok(InputObjectTypeDef {
description,
directives: self.directives()?,
name,
extend: self.u.arbitrary().unwrap_or(false),
fields,
})
}
}