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
use arbitrary::Result;
use crate::{description::Description, directive::Directive, name::Name, DocumentBuilder};
#[derive(Debug)]
pub struct ScalarTypeDef {
pub(crate) name: Name,
pub(crate) description: Option<Description>,
pub(crate) directives: Vec<Directive>,
pub(crate) extend: bool,
}
impl From<ScalarTypeDef> for apollo_encoder::ScalarDefinition {
fn from(scalar_def: ScalarTypeDef) -> Self {
let mut new_scalar_def = Self::new(scalar_def.name.into());
new_scalar_def.description(scalar_def.description.map(String::from));
scalar_def
.directives
.into_iter()
.for_each(|directive| new_scalar_def.directive(directive.into()));
if scalar_def.extend {
new_scalar_def.extend();
}
new_scalar_def
}
}
impl<'a> DocumentBuilder<'a> {
pub fn scalar_type_definition(&mut self) -> Result<ScalarTypeDef> {
let name = self.type_name()?;
let description = self
.u
.arbitrary()
.unwrap_or(false)
.then(|| self.description())
.transpose()?;
let directives = self.directives()?;
let extend = !directives.is_empty() && self.u.arbitrary().unwrap_or(false);
Ok(ScalarTypeDef {
name,
description,
directives,
extend,
})
}
}