libgraphql_core/operation/
mutation.rs

1use crate::ast;
2use crate::DirectiveAnnotation;
3use crate::loc;
4use crate::operation::FragmentRegistry;
5use crate::operation::MutationBuilder;
6use crate::operation::MutationBuildError;
7use crate::operation::OperationTrait;
8use crate::operation::OperationData;
9use crate::operation::SelectionSet;
10use crate::operation::Variable;
11use crate::schema::Schema;
12use indexmap::IndexMap;
13use inherent::inherent;
14
15/// Represents a Mutation operation over a given [Schema].
16#[derive(Clone, Debug, PartialEq)]
17pub struct Mutation<'schema: 'fragreg, 'fragreg>(
18    pub(super) OperationData<'schema, 'fragreg>,
19);
20
21#[inherent]
22impl<'schema: 'fragreg, 'fragreg> OperationTrait<
23    'schema,
24    'fragreg,
25    ast::operation::Mutation,
26    MutationBuildError,
27    MutationBuilder<'schema, 'fragreg>,
28> for Mutation<'schema, 'fragreg> {
29    /// Convenience wrapper around [MutationBuilder::new()].
30    pub fn builder(
31        schema: &'schema Schema,
32        fragment_registry: &'fragreg FragmentRegistry<'schema>,
33    ) -> MutationBuilder<'schema, 'fragreg> {
34        MutationBuilder::new(schema, fragment_registry)
35    }
36
37    /// The list of [`DirectiveAnnotation`]s applied to this [`Mutation`].
38    pub fn directives(&self) -> &Vec<DirectiveAnnotation> {
39        &self.0.directives
40    }
41
42    /// The [`loc::SourceLocation`] indicating where this [`Mutation`] operation
43    /// was defined.
44    pub fn def_location(&self) -> &loc::SourceLocation {
45        &self.0.def_location
46    }
47
48    /// Access the name of this [Mutation] (if one was specified).
49    pub fn name(&self) -> Option<&str> {
50        self.0.name.as_deref()
51    }
52
53    /// Access the [SelectionSet] defined for this [Mutation].
54    pub fn selection_set(&self) -> &SelectionSet<'fragreg> {
55        &self.0.selection_set
56    }
57
58    /// Access the [Variable]s defined on this [Mutation].
59    pub fn variables(&self) -> &IndexMap<String, Variable> {
60        &self.0.variables
61    }
62}