Class: GraphQL::Libgraphqlparser::Builder
- Inherits:
-
Object
- Object
- GraphQL::Libgraphqlparser::Builder
- Includes:
- GraphQL::Language
- Defined in:
- lib/graphql/libgraphqlparser/builder.rb
Overview
Keeps a stack of parse results, exposing the latest one. The C parser can call methods on this object, assuming they’ll be applied to the right object.
Instance Method Summary collapse
-
#add_value(string_value) ⇒ Object
This is for convenience from C.
- #begin_visit(node_class_name) ⇒ Object
- #current ⇒ Object
- #document ⇒ Object
- #end_visit ⇒ Object
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
9 10 11 |
# File 'lib/graphql/libgraphqlparser/builder.rb', line 9 def initialize @ast_stack = [] end |
Instance Method Details
#add_value(string_value) ⇒ Object
This is for convenience from C
64 65 66 |
# File 'lib/graphql/libgraphqlparser/builder.rb', line 64 def add_value(string_value) current.value = string_value end |
#begin_visit(node_class_name) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/graphql/libgraphqlparser/builder.rb', line 21 def begin_visit(node_class_name) # p "--> BEGIN #{node_class_name}" node_class = Nodes.const_get(node_class_name) node = node_class.new case node when Nodes::OperationDefinition, Nodes::FragmentDefinition current.definitions << node when Nodes::VariableDefinition current.variables << node when Nodes::VariableIdentifier if current.is_a?(Nodes::VariableDefinition) node = current else current.value = node end when Nodes::Directive current.directives << node when Nodes::Argument current.arguments << node when Nodes::InlineFragment, Nodes::FragmentSpread, Nodes::Field current.selections << node when Nodes::TypeName, Nodes::ListType, Nodes::NonNullType # Using ||= because FragmentDefinition has already assigned # this as a plain string :( current.type ||= node when Nodes::ArrayLiteral # mutability! 🎉 current.value = node.values when Nodes::InputObject current.value = node end @ast_stack.push(node) node end |
#current ⇒ Object
17 18 19 |
# File 'lib/graphql/libgraphqlparser/builder.rb', line 17 def current @ast_stack.last end |
#document ⇒ Object
13 14 15 |
# File 'lib/graphql/libgraphqlparser/builder.rb', line 13 def document @ast_stack.first end |
#end_visit ⇒ Object
57 58 59 60 61 |
# File 'lib/graphql/libgraphqlparser/builder.rb', line 57 def end_visit removed = @ast_stack.pop # p "--> END #{removed}" removed end |