libgraphql_core/operation/
operation.rs

1use indexmap::IndexMap;
2
3use crate::loc;
4use crate::operation::Query;
5use crate::operation::Mutation;
6use crate::operation::SelectionSet;
7use crate::operation::Subscription;
8use crate::operation::Variable;
9use crate::DirectiveAnnotation;
10use std::boxed::Box;
11
12#[derive(Clone, Debug, PartialEq)]
13pub enum Operation<'schema: 'fragreg, 'fragreg> {
14    Query(Box<Query<'schema, 'fragreg>>),
15    Mutation(Box<Mutation<'schema, 'fragreg>>),
16    Subscription(Box<Subscription<'schema, 'fragreg>>),
17}
18impl<'schema: 'fragreg, 'fragreg> Operation<'schema, 'fragreg> {
19    pub fn def_location(&self) -> &loc::SourceLocation {
20        match self {
21            Self::Mutation(op) => op.def_location(),
22            Self::Query(op) => op.def_location(),
23            Self::Subscription(op) => op.def_location(),
24        }
25    }
26
27    pub fn directives(&self) -> &Vec<DirectiveAnnotation> {
28        match self {
29            Self::Mutation(op) => op.directives(),
30            Self::Query(op) => op.directives(),
31            Self::Subscription(op) => op.directives(),
32        }
33    }
34
35    pub fn name(&self) -> Option<&str> {
36        match self {
37            Self::Mutation(op) => op.name(),
38            Self::Query(op) => op.name(),
39            Self::Subscription(op) => op.name(),
40        }
41    }
42
43    pub fn selection_set(&self) -> &SelectionSet<'fragreg> {
44        match self {
45            Self::Mutation(op) => op.selection_set(),
46            Self::Query(op) => op.selection_set(),
47            Self::Subscription(op) => op.selection_set(),
48        }
49    }
50
51    pub fn variables(&self) -> &IndexMap<String, Variable> {
52        match self {
53            Self::Mutation(op) => op.variables(),
54            Self::Query(op) => op.variables(),
55            Self::Subscription(op) => op.variables(),
56        }
57    }
58}