libgraphql_core/operation/
subscription.rs

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