Sha256: 1caddb222297cd8de4d51879f3908fac5aa54ab08ea1498979bc3c1af62873cc

Contents?: true

Size: 1002 Bytes

Versions: 2

Compression:

Stored size: 1002 Bytes

Contents

module Giraph
  # Proc-like class to allow declerative links to external
  # resolution handlers (so the "definition" gem can stay pure resolution-wise)
  class Resolver
    class UnknownOperation < StandardError; end

    def self.for(method_name)
      new(method_name)
    end

    def initialize(method_name)
      @method_name = method_name
    end

    # Resolves the field by calling the previously given method
    # on the registered Resolver object for the current operation
    # type (currently query or mutation)
    def call(obj, args, ctx)
      # Find out operation type (query, mutation, etc.)
      op_type = ctx.query.selected_operation.operation_type.to_sym

      # Ensure there is a registered resolver for it
      unless (resolver = ctx[:__giraph_resolver__][op_type])
        raise UnknownOperation, "No resolver found for '#{op_type}' op type"
      end

      # Call the requested method on resolver
      resolver.public_send(@method_name, obj, args, ctx)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
giraph-0.1.1 lib/giraph/resolver.rb
giraph-0.1.0 lib/giraph/resolver.rb