async_graphql/validation/rules/
upload_file.rs

1use crate::{
2    Name, Positioned,
3    parser::types::{OperationDefinition, OperationType},
4    validation::visitor::{Visitor, VisitorContext},
5};
6
7#[derive(Default)]
8pub struct UploadFile;
9
10impl<'a> Visitor<'a> for UploadFile {
11    fn enter_operation_definition(
12        &mut self,
13        ctx: &mut VisitorContext<'a>,
14        _name: Option<&'a Name>,
15        operation_definition: &'a Positioned<OperationDefinition>,
16    ) {
17        for var in &operation_definition.node.variable_definitions {
18            if let Some(ty) = ctx
19                .registry
20                .concrete_type_by_parsed_type(&var.node.var_type.node)
21            {
22                if operation_definition.node.ty != OperationType::Mutation && ty.name() == "Upload"
23                {
24                    ctx.report_error(
25                        vec![var.pos],
26                        "The Upload type is only allowed to be defined on a mutation",
27                    );
28                }
29            }
30        }
31    }
32}