libgraphql_core/operation/
query.rs

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