libgraphql_core/operation/
executable_document.rs

1use crate::operation::ExecutableDocumentBuilder;
2use crate::operation::FragmentRegistry;
3use crate::operation::Operation;
4use crate::schema::Schema;
5
6/// Represents a GraphQL
7/// ["exectuable document"](https://spec.graphql.org/October2021/#ExecutableDocument).
8/// As [described in the GraphQL spec](https://spec.graphql.org/October2021/#sel-EAFPNCAACEB6la):
9///
10/// > `Document`s are only executable by a GraphQL service if they are
11/// > [`ExecutableDocument`] and contain at least one `OperationDefinition`.
12/// > A `Document` which contains `TypeSystemDefinitionOrExtension` must not be
13/// > executed; GraphQL execution services which receive a `Document` containing
14/// > these should return a descriptive error.
15///
16/// Generally you'll only want to work with [`ExecutableDocument`]s
17/// only when you're working with a file that groups multiple operations and/or
18/// fragments in one place. If you're only working with a single [`Operation`]
19/// or [`Fragment`](crate::operation::Fragment) at a time, though,
20/// you're better off working more directly with those types.
21#[derive(Clone, Debug)]
22pub struct ExecutableDocument<'schema: 'fragreg, 'fragreg> {
23    pub(super) fragment_registry: &'fragreg FragmentRegistry<'schema>,
24    pub(super) operations: Vec<Operation<'schema, 'fragreg>>,
25    pub(super) schema: &'schema Schema,
26}
27
28impl<'schema, 'fragreg> ExecutableDocument<'schema, 'fragreg> {
29    /// Convenience wrapper around [`ExecutableDocumentBuilder::new()`].
30    pub fn builder(
31        schema: &'schema Schema,
32        fragment_registry: &'fragreg FragmentRegistry<'schema>,
33    ) -> ExecutableDocumentBuilder<'schema, 'fragreg> {
34        ExecutableDocumentBuilder::new(schema, fragment_registry)
35    }
36
37    pub fn fragment_registry(&self) -> &'fragreg FragmentRegistry<'schema> {
38        self.fragment_registry
39    }
40
41    pub fn operations(&self) -> &Vec<Operation<'schema, 'fragreg>> {
42        &self.operations
43    }
44
45    pub fn schema(&self) -> &'schema Schema {
46        self.schema
47    }
48}