Module: ElasticGraph::GraphQL::Resolvers::ResolvableValue

Defined in:
lib/elastic_graph/graphql/resolvers/resolvable_value.rb

Overview

A class builder that is just like ‘Data` and also adapts itself to our resolver interface. Can resolve any field that is defined in `schema_element_names` and also has a corresponding method definition.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(*fields, &block) ⇒ Object

‘MemoizableData.define` provides the following methods:



22
23
24
25
26
27
28
29
# File 'lib/elastic_graph/graphql/resolvers/resolvable_value.rb', line 22

def self.new(*fields, &block)
  Support::MemoizableData.define(:schema_element_names, *fields) do
    # @implements ResolvableValueClass
    include ResolvableValue
    # @type var block: (^() -> void)?
    class_exec(&block) if block
  end
end

Instance Method Details

#can_resolve?(field:, object:) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/elastic_graph/graphql/resolvers/resolvable_value.rb', line 36

def can_resolve?(field:, object:)
  method_name = schema_element_names.canonical_name_for(field.name)
  !!method_name && respond_to?(method_name)
end

#resolve(field:, object:, context:, args:, lookahead:) ⇒ Object



31
32
33
34
# File 'lib/elastic_graph/graphql/resolvers/resolvable_value.rb', line 31

def resolve(field:, object:, context:, args:, lookahead:)
  method_name = canonical_name_for(field.name, "Field")
  public_send(method_name, **args_to_canonical_form(args))
end