pub trait Folder<'a> {
Show 22 methods
// Provided methods
fn enter_operation(
&mut self,
_ctx: &'a ASTContext,
operation: OperationDefinition<'a>,
_info: &VisitInfo,
) -> Result<OperationDefinition<'a>> { ... }
fn leave_operation(
&mut self,
_ctx: &'a ASTContext,
operation: OperationDefinition<'a>,
_info: &VisitInfo,
) -> Result<OperationDefinition<'a>> { ... }
fn enter_fragment(
&mut self,
_ctx: &'a ASTContext,
fragment: FragmentDefinition<'a>,
_info: &VisitInfo,
) -> Result<FragmentDefinition<'a>> { ... }
fn leave_fragment(
&mut self,
_ctx: &'a ASTContext,
fragment: FragmentDefinition<'a>,
_info: &VisitInfo,
) -> Result<FragmentDefinition<'a>> { ... }
fn variable_definitions(
&mut self,
_ctx: &'a ASTContext,
var_defs: VariableDefinitions<'a>,
_info: &VisitInfo,
) -> Result<VariableDefinitions<'a>> { ... }
fn variable_definition(
&mut self,
_ctx: &'a ASTContext,
var_def: VariableDefinition<'a>,
_info: &VisitInfo,
) -> Result<VariableDefinition<'a>> { ... }
fn selection_set(
&mut self,
_ctx: &'a ASTContext,
selection_set: SelectionSet<'a>,
_info: &VisitInfo,
) -> Result<SelectionSet<'a>> { ... }
fn enter_fragment_spread(
&mut self,
_ctx: &'a ASTContext,
fragment_spread: FragmentSpread<'a>,
_info: &VisitInfo,
) -> Result<FragmentSpread<'a>> { ... }
fn leave_fragment_spread(
&mut self,
_ctx: &'a ASTContext,
fragment_spread: FragmentSpread<'a>,
_info: &VisitInfo,
) -> Result<FragmentSpread<'a>> { ... }
fn enter_inline_fragment(
&mut self,
_ctx: &'a ASTContext,
inline_fragment: InlineFragment<'a>,
_info: &VisitInfo,
) -> Result<InlineFragment<'a>> { ... }
fn leave_inline_fragment(
&mut self,
_ctx: &'a ASTContext,
inline_fragment: InlineFragment<'a>,
_info: &VisitInfo,
) -> Result<InlineFragment<'a>> { ... }
fn enter_field(
&mut self,
_ctx: &'a ASTContext,
field: Field<'a>,
_info: &VisitInfo,
) -> Result<Field<'a>> { ... }
fn leave_field(
&mut self,
_ctx: &'a ASTContext,
field: Field<'a>,
_info: &VisitInfo,
) -> Result<Field<'a>> { ... }
fn directives(
&mut self,
_ctx: &'a ASTContext,
directives: Directives<'a>,
_info: &VisitInfo,
) -> Result<Directives<'a>> { ... }
fn enter_directive(
&mut self,
_ctx: &'a ASTContext,
directive: Directive<'a>,
_info: &VisitInfo,
) -> Result<Directive<'a>> { ... }
fn leave_directive(
&mut self,
_ctx: &'a ASTContext,
directive: Directive<'a>,
_info: &VisitInfo,
) -> Result<Directive<'a>> { ... }
fn arguments(
&mut self,
_ctx: &'a ASTContext,
arguments: Arguments<'a>,
_info: &VisitInfo,
) -> Result<Arguments<'a>> { ... }
fn argument(
&mut self,
_ctx: &'a ASTContext,
argument: Argument<'a>,
_info: &VisitInfo,
) -> Result<Argument<'a>> { ... }
fn value(
&mut self,
_ctx: &'a ASTContext,
value: Value<'a>,
_info: &VisitInfo,
) -> Result<Value<'a>> { ... }
fn of_type(
&mut self,
_ctx: &'a ASTContext,
of_type: Type<'a>,
_info: &VisitInfo,
) -> Result<Type<'a>> { ... }
fn variable(
&mut self,
_ctx: &'a ASTContext,
var: Variable<'a>,
_info: &VisitInfo,
) -> Result<Variable<'a>> { ... }
fn named_type(
&mut self,
_ctx: &'a ASTContext,
name: NamedType<'a>,
_info: &VisitInfo,
) -> Result<NamedType<'a>> { ... }
}
Expand description
Trait for a folder that carries methods that are called as callback while AST nodes implementing the folder pattern are traversed and edited.
A Folder is used to traverse an GraphQL AST top-to-bottom, depth-first and to replace the AST’s nodes by calling the Folder’s callbacks and replacing the AST nodes one by one. After an AST Node is folded it’s an entirely new copy, separate from the input AST, which remains untouched.
All callbacks have a default no-op implementation that return the input AST Node and hence only
create an unchanged copy of the AST.
The callbacks receive a reference to the ASTContext
and must return the altered (or
unchanged) node that’s placed into the new AST using a Result. This can be used to also
return an error and stop the folding.
This pattern is applicable to any AST node that implements the FoldNode
trait.
Provided Methods§
Sourcefn enter_operation(
&mut self,
_ctx: &'a ASTContext,
operation: OperationDefinition<'a>,
_info: &VisitInfo,
) -> Result<OperationDefinition<'a>>
fn enter_operation( &mut self, _ctx: &'a ASTContext, operation: OperationDefinition<'a>, _info: &VisitInfo, ) -> Result<OperationDefinition<'a>>
Folds an OperationDefinition
into a new node as part of a new, transformed AST, before
the Operation is folded recursively
Sourcefn leave_operation(
&mut self,
_ctx: &'a ASTContext,
operation: OperationDefinition<'a>,
_info: &VisitInfo,
) -> Result<OperationDefinition<'a>>
fn leave_operation( &mut self, _ctx: &'a ASTContext, operation: OperationDefinition<'a>, _info: &VisitInfo, ) -> Result<OperationDefinition<'a>>
Folds an OperationDefinition
into a new node as part of a new, transformed AST, after
the Operation has been folded.
Sourcefn enter_fragment(
&mut self,
_ctx: &'a ASTContext,
fragment: FragmentDefinition<'a>,
_info: &VisitInfo,
) -> Result<FragmentDefinition<'a>>
fn enter_fragment( &mut self, _ctx: &'a ASTContext, fragment: FragmentDefinition<'a>, _info: &VisitInfo, ) -> Result<FragmentDefinition<'a>>
Folds a FragmentDefinition
into a new node as part of a new, transformed AST, before the
FragmentDefinition is folded recursively.
Sourcefn leave_fragment(
&mut self,
_ctx: &'a ASTContext,
fragment: FragmentDefinition<'a>,
_info: &VisitInfo,
) -> Result<FragmentDefinition<'a>>
fn leave_fragment( &mut self, _ctx: &'a ASTContext, fragment: FragmentDefinition<'a>, _info: &VisitInfo, ) -> Result<FragmentDefinition<'a>>
Folds a FragmentDefinition
into a new node as part of a new, transformed AST, after the
FragmentDefinition has been folded.
Sourcefn variable_definitions(
&mut self,
_ctx: &'a ASTContext,
var_defs: VariableDefinitions<'a>,
_info: &VisitInfo,
) -> Result<VariableDefinitions<'a>>
fn variable_definitions( &mut self, _ctx: &'a ASTContext, var_defs: VariableDefinitions<'a>, _info: &VisitInfo, ) -> Result<VariableDefinitions<'a>>
Folds a VariableDefinitions
node into a new node as part of a new, transformed AST.
Sourcefn variable_definition(
&mut self,
_ctx: &'a ASTContext,
var_def: VariableDefinition<'a>,
_info: &VisitInfo,
) -> Result<VariableDefinition<'a>>
fn variable_definition( &mut self, _ctx: &'a ASTContext, var_def: VariableDefinition<'a>, _info: &VisitInfo, ) -> Result<VariableDefinition<'a>>
Folds a VariableDefinition
into a new node as part of a new, transformed AST.
Sourcefn selection_set(
&mut self,
_ctx: &'a ASTContext,
selection_set: SelectionSet<'a>,
_info: &VisitInfo,
) -> Result<SelectionSet<'a>>
fn selection_set( &mut self, _ctx: &'a ASTContext, selection_set: SelectionSet<'a>, _info: &VisitInfo, ) -> Result<SelectionSet<'a>>
Folds a SelectionSet
into a new node as part of a new, transformed AST.
Sourcefn enter_fragment_spread(
&mut self,
_ctx: &'a ASTContext,
fragment_spread: FragmentSpread<'a>,
_info: &VisitInfo,
) -> Result<FragmentSpread<'a>>
fn enter_fragment_spread( &mut self, _ctx: &'a ASTContext, fragment_spread: FragmentSpread<'a>, _info: &VisitInfo, ) -> Result<FragmentSpread<'a>>
Folds a FragmentSpread
node into a new node as part of a new, transformed AST, before
the FragmentSpread is folded recursively.
Sourcefn leave_fragment_spread(
&mut self,
_ctx: &'a ASTContext,
fragment_spread: FragmentSpread<'a>,
_info: &VisitInfo,
) -> Result<FragmentSpread<'a>>
fn leave_fragment_spread( &mut self, _ctx: &'a ASTContext, fragment_spread: FragmentSpread<'a>, _info: &VisitInfo, ) -> Result<FragmentSpread<'a>>
Folds a FragmentSpread
node into a new node as part of a new, transformed AST, after
the FragmentSpread has been folded.
Sourcefn enter_inline_fragment(
&mut self,
_ctx: &'a ASTContext,
inline_fragment: InlineFragment<'a>,
_info: &VisitInfo,
) -> Result<InlineFragment<'a>>
fn enter_inline_fragment( &mut self, _ctx: &'a ASTContext, inline_fragment: InlineFragment<'a>, _info: &VisitInfo, ) -> Result<InlineFragment<'a>>
Folds an InlineFragment
into a new node as part of a new, transformed AST, before the
InlineFragment is folded recursively.
Sourcefn leave_inline_fragment(
&mut self,
_ctx: &'a ASTContext,
inline_fragment: InlineFragment<'a>,
_info: &VisitInfo,
) -> Result<InlineFragment<'a>>
fn leave_inline_fragment( &mut self, _ctx: &'a ASTContext, inline_fragment: InlineFragment<'a>, _info: &VisitInfo, ) -> Result<InlineFragment<'a>>
Folds an InlineFragment
into a new node as part of a new, transformed AST, after the
InlineFragment has been folded.
Sourcefn enter_field(
&mut self,
_ctx: &'a ASTContext,
field: Field<'a>,
_info: &VisitInfo,
) -> Result<Field<'a>>
fn enter_field( &mut self, _ctx: &'a ASTContext, field: Field<'a>, _info: &VisitInfo, ) -> Result<Field<'a>>
Folds a Field into a new node as part of a new, transformed AST, before the Field is folded recursively.
Sourcefn leave_field(
&mut self,
_ctx: &'a ASTContext,
field: Field<'a>,
_info: &VisitInfo,
) -> Result<Field<'a>>
fn leave_field( &mut self, _ctx: &'a ASTContext, field: Field<'a>, _info: &VisitInfo, ) -> Result<Field<'a>>
Folds a Field into a new node as part of a new, transformed AST, after the field has been folded.
Sourcefn directives(
&mut self,
_ctx: &'a ASTContext,
directives: Directives<'a>,
_info: &VisitInfo,
) -> Result<Directives<'a>>
fn directives( &mut self, _ctx: &'a ASTContext, directives: Directives<'a>, _info: &VisitInfo, ) -> Result<Directives<'a>>
Folds a Directives node into a new node as part of a new, transformed AST.
Sourcefn enter_directive(
&mut self,
_ctx: &'a ASTContext,
directive: Directive<'a>,
_info: &VisitInfo,
) -> Result<Directive<'a>>
fn enter_directive( &mut self, _ctx: &'a ASTContext, directive: Directive<'a>, _info: &VisitInfo, ) -> Result<Directive<'a>>
Folds a Directive into a new node as part of a new, transformed AST, before the Directive is folded recursively.
Sourcefn leave_directive(
&mut self,
_ctx: &'a ASTContext,
directive: Directive<'a>,
_info: &VisitInfo,
) -> Result<Directive<'a>>
fn leave_directive( &mut self, _ctx: &'a ASTContext, directive: Directive<'a>, _info: &VisitInfo, ) -> Result<Directive<'a>>
Folds a Directive into a new node as part of a new, transformed AST, after the Directive has been folded.
Sourcefn arguments(
&mut self,
_ctx: &'a ASTContext,
arguments: Arguments<'a>,
_info: &VisitInfo,
) -> Result<Arguments<'a>>
fn arguments( &mut self, _ctx: &'a ASTContext, arguments: Arguments<'a>, _info: &VisitInfo, ) -> Result<Arguments<'a>>
Folds a Arguments node into a new node as part of a new, transformed AST.
Sourcefn argument(
&mut self,
_ctx: &'a ASTContext,
argument: Argument<'a>,
_info: &VisitInfo,
) -> Result<Argument<'a>>
fn argument( &mut self, _ctx: &'a ASTContext, argument: Argument<'a>, _info: &VisitInfo, ) -> Result<Argument<'a>>
Folds an Argument into a new node as part of a new, transformed AST.
Sourcefn value(
&mut self,
_ctx: &'a ASTContext,
value: Value<'a>,
_info: &VisitInfo,
) -> Result<Value<'a>>
fn value( &mut self, _ctx: &'a ASTContext, value: Value<'a>, _info: &VisitInfo, ) -> Result<Value<'a>>
Folds a Value node into a new node as part of a new, transformed AST.
Sourcefn of_type(
&mut self,
_ctx: &'a ASTContext,
of_type: Type<'a>,
_info: &VisitInfo,
) -> Result<Type<'a>>
fn of_type( &mut self, _ctx: &'a ASTContext, of_type: Type<'a>, _info: &VisitInfo, ) -> Result<Type<'a>>
Folds a Type node into a new node as part of a new, transformed AST.
Sourcefn variable(
&mut self,
_ctx: &'a ASTContext,
var: Variable<'a>,
_info: &VisitInfo,
) -> Result<Variable<'a>>
fn variable( &mut self, _ctx: &'a ASTContext, var: Variable<'a>, _info: &VisitInfo, ) -> Result<Variable<'a>>
Folds a Variable node into a new node as part of a new, transformed AST.
Sourcefn named_type(
&mut self,
_ctx: &'a ASTContext,
name: NamedType<'a>,
_info: &VisitInfo,
) -> Result<NamedType<'a>>
fn named_type( &mut self, _ctx: &'a ASTContext, name: NamedType<'a>, _info: &VisitInfo, ) -> Result<NamedType<'a>>
Folds a NamedType
node into a new node as part of a new, transformed AST.