libgraphql_core/
directive_annotation_builder.rs

1use crate::ast;
2use crate::DirectiveAnnotation;
3use crate::loc;
4use crate::types::NamedDirectiveRef;
5use crate::Value;
6use indexmap::IndexMap;
7
8#[derive(Debug)]
9pub struct DirectiveAnnotationBuilder;
10impl DirectiveAnnotationBuilder {
11    pub fn from_ast(
12        annotated_item_srcloc: &loc::SourceLocation,
13        directives: &[ast::operation::Directive],
14    ) -> Vec<DirectiveAnnotation> {
15        directives.iter().map(|ast_annot| {
16            let annot_srcloc =
17                annotated_item_srcloc.with_ast_position(&ast_annot.position);
18            let mut args = IndexMap::new();
19            for (arg_name, ast_arg) in ast_annot.arguments.iter() {
20                args.insert(
21                    arg_name.to_string(),
22                    Value::from_ast(ast_arg, &annot_srcloc),
23                );
24            }
25            DirectiveAnnotation {
26                args,
27                directive_ref: NamedDirectiveRef::new(
28                    &ast_annot.name,
29                    annot_srcloc,
30                ),
31            }
32        }).collect()
33    }
34}