Module executable

Source
Expand description

High-level representation of an executable document, which can contain operations and fragments.

Compared to an ast::Document which follows closely the structure of GraphQL syntax, an ExecutableDocument interpreted in the context of a valid Schema and contains typing information.

In some cases like SelectionSet, this module and the ast module define different Rust types with the same names. In other cases like Directive there is no data structure difference needed, so this module reuses and publicly re-exports some Rust types from the ast module.

§“Build” errors

As a result of how ExecutableDocument containing typing information, not all AST documents (even if filtering out type system definitions) can be fully represented: creating a ExecutableDocument can cause errors (on top of any potential syntax error) for cases like selecting a field not defined in the schema.

When such errors (or in ExecutableDocument::parse, syntax errors) happen, a partial document is returned together with a list of diagnostics.

§Structural sharing and mutation

Like in AST, many parts of a ExecutableDocument are reference-counted with Node. This allows sharing nodes between documents without cloning entire subtrees. To modify a node, the make_mut method provides copy-on-write semantics.

§Validation

The Validation section of the GraphQL specification defines validation rules beyond syntax errors and errors detected while constructing a ExecutableDocument. The validate method returns either:

If there is no mutation needed between parsing and validation, ExecutableDocument::parse_and_validate does both in one step.

§Serialization

ExecutableDocument and other types types implement Display and ToString by serializing to GraphQL syntax with a default configuration. serialize methods return a builder that has chaining methods for setting serialization configuration, and also implements Display and ToString.

Re-exports§

pub use crate::ast::Argument;
pub use crate::ast::Directive;
pub use crate::ast::DirectiveList;
pub use crate::ast::NamedType;
pub use crate::ast::OperationType;
pub use crate::ast::Type;
pub use crate::ast::Value;
pub use crate::ast::VariableDefinition;
pub use crate::Name;

Structs§

ExecutableDocument
Executable definitions, annotated with type information
Field
A Field selection, linked to the corresponding field definition in the schema.
FieldSet
FieldSet information created for FieldSet parsing in @requires directive. Annotated with type information.
Fragment
A FragmentDefinition annotated with type information.
FragmentSpread
A FragmentSpread annotated with type information.
InlineFragment
A InlineFragment annotated with type information.
Operation
An OperationDefinition annotated with type information.
OperationMap
Operations definitions for a given executable document
SelectionSet
A SelectionSet annotated with type information.

Enums§

Selection
A Selection annotated with type information.

Type Aliases§

FragmentMap
Definitions of named fragments for a given executable document