1use graphql_parser::schema::Field;
2use graphql_parser::Pos;
3
4use super::argument::InputValueType;
5use super::directive::GqlDirective;
6use super::value_type::GqlValueType;
7
8#[derive(Debug, Clone)]
9pub struct FieldType {
10 pub name: String,
11 pub description: Option<String>,
12 pub position: Pos,
13 pub meta_type: GqlValueType,
14 pub arguments: Vec<InputValueType>,
15 pub directives: Vec<GqlDirective>,
16}
17
18impl FieldType {
19 pub fn from_vec_field(fields: Vec<Field<'_, String>>) -> Vec<FieldType> {
20 fields.into_iter().map(FieldType::from).collect()
21 }
22
23 pub fn is_deprecated(&self) -> bool {
24 for dir in &self.directives {
25 if dir.name == "deprecated" {
26 return true;
27 }
28 continue;
29 }
30 false
31 }
32}
33
34impl<'a> From<Field<'a, String>> for FieldType {
35 fn from(field: Field<'a, String>) -> Self {
36 let meta_type = GqlValueType::from(field.field_type);
37 let directives = GqlDirective::from_vec_directive(field.directives);
38 let arguments = InputValueType::from_vec_input_value(field.arguments);
39
40 FieldType {
41 name: field.name,
42 description: field.description,
43 position: field.position,
44 meta_type,
45 directives,
46 arguments,
47 }
48 }
49}