Module: Giraph::Extensions::Field

Included in:
GraphQL::Field
Defined in:
lib/giraph/extensions/field.rb

Instance Method Summary collapse

Instance Method Details

#resolve(object, arguments, context) ⇒ Object

Wrap the ‘resolve’ method on Field so that we can intercept the registered resolution Proc and resolve on already-resolved values from the JSON returned to the sub-query through the remote endpoint



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/giraph/extensions/field.rb', line 9

def resolve(object, arguments, context)
  # Giraph always parses a remote response with a special Hash
  # class called 'Giraph::Remote::Response', which is a no-op sub-class
  # of Hash. This way we can easily recognize this special
  # "resolve on already resolved response" case while still
  # allowing regular Hash to be resolved normally.
  if object.instance_of? Giraph::Remote::Response
    # If the field was aliased, response will be keyed by the alias
    field = context.ast_node.alias || context.ast_node.name
    object[field.to_sym]
  else
    # Not Giraph, let it through...
    super
  end
end