Expand description
§GraphQL Query Language AST
The graphql_query::ast
module contains the GraphQL query language AST and traits to parse and
print the AST. The AST implemented in this crate is specialized to only implement the
client-side GraphQL query language that clients use to make requests to a GraphQL service.
Reference
It’s easiest to use this module by importing all of it, however, its three main parts are:
ASTContext
, a context containing an arena that defines the lifetime for an ASTParseNode
, a trait using which AST Nodes are parsed from source textPrintNode
, a trait using which AST Nodes are printed into source text
The following workflow describes the minimum that’s done using this module and while an AST Context is active in the given scope.
use graphql_query::ast::*;
// Create an AST Context for a document
let ctx = ASTContext::new();
// Parse a source text into a Document AST root node
let ast = Document::parse(&ctx, "{ field }").unwrap();
// Print the Document node to an output String
let output = ast.print();
Structs§
- ASTContext
- A context for a GraphQL document which holds an arena allocator.
- Argument
- AST Node for an Argument, which carries a name and a value.
- Arguments
- AST Node for a list of Arguments, which are similar to parameterized inputs to a function.
- Boolean
Value - AST Node of a boolean value
- Directive
- AST Node for GraphQL Directives, which provide a way to describe alternate behavior in GraphQL.
- Directives
- AST Node for lists of GraphQL Directives, which provide a way to describe alternate behavior in GraphQL.
- Document
- AST Root Node for a GraphQL query language document. This contains one or more definitions of fragments or operations.
- Enum
Value - AST Node of an enum value.
- Field
- AST Node for Fields, which can be likened to functions or properties on a parent object.
- Float
Value - AST Node of a floating point value.
- Fragment
Definition - AST Node for a Fragment definition with an additional Selection Set.
- Fragment
Spread - AST Node for a Fragment Spread, which refers to a
FragmentDefinition
with an additionalSelectionSet
. - Inline
Fragment - AST Node for an inline Fragment definition with an additional
SelectionSet
. This may only be applied when the type condition matches or when no type condition is present. - IntValue
- AST Node of an integer value.
- List
Value - AST Node for a List of values.
- Named
Type - AST Node for a type name.
- Object
Field - AST Node for a field of an Object value.
- Object
Value - AST Node for an Object value, which is a list of Object fields.
- Operation
Definition - AST Node for an Operation Definition, which defines the entrypoint for GraphQL’s execution.
- Selection
Set - AST Node for Selection Sets, which provide a way to select more information on a given parent.
- String
Value - AST Node of a string value.
- Variable
- AST Node of a variable identifier value.
- Variable
Definition - AST Node for a variable definition.
- Variable
Definitions
Enums§
- ASTKind
- An enum of identifiers representing AST nodes.
- Definition
- AST Node for a Definition inside a query language document, which may either be an Operation Definition or a Fragment Definition.
- Operation
Kind - AST Node for a kind of operation, as referred to by an
OperationDefinition
. - Selection
- AST Node of a selection as contained inside a
SelectionSet
. - Type
- AST Node for a type reference.
- Value
- AST Node of possible input values in GraphQL.
Traits§
- Default
In - Parse
Node - Trait for parsing AST Nodes from source texts using recursive descent and a lexer.
- Print
Node - Trait for printing AST Nodes to a new String allocated on the heap.
This is implemented by all AST Nodes and can hence be used to granularly print GraphQL language.
However, mostly this will be used via
Document::print
. - Skippable
- Trait implemented by all AST nodes that can be skipped via standard skip/include directives.
- With
Directives - Trait implemented by all ast nodes that can have directives attached.
Type Aliases§
- Variables
- Map of AST Values for GraphQL Variables