Class: Giraph::Remote::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/giraph/remote/query.rb

Overview

Field resolver to plug a remote GraphQL query root into a local type

Direct Known Subclasses

Mutation

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, connector, &block) ⇒ Query

Returns a new instance of Query.



13
14
15
16
17
# File 'lib/giraph/remote/query.rb', line 13

def initialize(endpoint, connector, &block)
  @endpoint = endpoint
  @evaluator = block || method(:default_evaluator)
  @connector = connector
end

Class Method Details

.bind(endpoint, &block) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/giraph/remote/query.rb', line 5

def self.bind(endpoint, &block)
  new(
    endpoint,
    Remote::Connector.new(endpoint),
    &block
  )
end

Instance Method Details

#call(obj, args, ctx) ⇒ Object

Reconstructs a valid GraphQL root-query from the current field in question, including all variables and params, hands over to connector to execute remotely.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/giraph/remote/query.rb', line 22

def call(obj, args, ctx)
  # Given an evaluator block, continue if only it evaluates to non-nil!
  return unless (remote_root = @evaluator.call(obj, args, ctx))

  subquery = Subquery.new(ctx)

  # Continue with remote query execution
  connector.resolve(
    ctx,
    query_string(subquery),
    query_variables(subquery, remote_root)
  )
end