Class: GraphQL::InternalRepresentation::Rewrite::VisitDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/internal_representation/rewrite.rb

Instance Method Summary collapse

Constructor Details

#initialize(context, definitions, nodes_stack, scopes_stack) ⇒ VisitDefinition

Returns a new instance of VisitDefinition.



165
166
167
168
169
170
171
# File 'lib/graphql/internal_representation/rewrite.rb', line 165

def initialize(context, definitions, nodes_stack, scopes_stack)
  @context = context
  @query = context.query
  @definitions = definitions
  @nodes_stack = nodes_stack
  @scopes_stack = scopes_stack
end

Instance Method Details

#enter(ast_node, ast_parent) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/graphql/internal_representation/rewrite.rb', line 173

def enter(ast_node, ast_parent)
  # Either QueryType or the fragment type condition
  owner_type = @context.type_definition && @context.type_definition.unwrap
  defn_name = ast_node.name

  node = Node.new(
    parent: nil,
    name: defn_name,
    owner_type: owner_type,
    query: @query,
    ast_nodes: [ast_node],
    return_type: @context.type_definition,
  )

  @definitions[defn_name] = node
  @scopes_stack.push(Scope.new(@query, owner_type))
  @nodes_stack.push([node])
end

#leave(ast_node, ast_parent) ⇒ Object



192
193
194
195
# File 'lib/graphql/internal_representation/rewrite.rb', line 192

def leave(ast_node, ast_parent)
  @nodes_stack.pop
  @scopes_stack.pop
end