Module ast

Source
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 AST
  • ParseNode, a trait using which AST Nodes are parsed from source text
  • PrintNode, 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.
BooleanValue
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.
EnumValue
AST Node of an enum value.
Field
AST Node for Fields, which can be likened to functions or properties on a parent object.
FloatValue
AST Node of a floating point value.
FragmentDefinition
AST Node for a Fragment definition with an additional Selection Set.
FragmentSpread
AST Node for a Fragment Spread, which refers to a FragmentDefinition with an additional SelectionSet.
InlineFragment
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.
ListValue
AST Node for a List of values.
NamedType
AST Node for a type name.
ObjectField
AST Node for a field of an Object value.
ObjectValue
AST Node for an Object value, which is a list of Object fields.
OperationDefinition
AST Node for an Operation Definition, which defines the entrypoint for GraphQL’s execution.
SelectionSet
AST Node for Selection Sets, which provide a way to select more information on a given parent.
StringValue
AST Node of a string value.
Variable
AST Node of a variable identifier value.
VariableDefinition
AST Node for a variable definition.
VariableDefinitions

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.
OperationKind
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§

DefaultIn
ParseNode
Trait for parsing AST Nodes from source texts using recursive descent and a lexer.
PrintNode
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.
WithDirectives
Trait implemented by all ast nodes that can have directives attached.

Type Aliases§

Variables
Map of AST Values for GraphQL Variables