Class: GraphQL::Schema::BuildFromDefinition::Builder::FieldResolveMethods

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/schema/build_from_definition.rb

Overview

Every field's resolve methods share these procs. They use the method's name to find the field.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ FieldResolveMethods

Returns a new instance of FieldResolveMethods.



796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
# File 'lib/graphql/schema/build_from_definition.rb', line 796

def initialize
  @method_names = Hash.new { |h, field_name| h[field_name] = -"resolve_field_#{field_name}" }
  field_names = @field_names = {}
  @instance_method_proc = proc { |**args|
    #: self as GraphQL::Schema::Object
    owner = self.class
    field_instance = context.types.field(owner, field_names[__method__])
    context.schema.definition_default_resolve.call(owner, field_instance, object, args, context)
  }
  @singleton_method_proc = proc { |objects, context, **args|
    field_instance = context.types.field(self, field_names[__method__])
    objects.map do |object|
      context.schema.definition_default_resolve.call(self, field_instance, object, args, context)
    end
  }
end

Instance Attribute Details

#field_names ⇒ Object (readonly)

Field names by resolve method name



814
815
816
# File 'lib/graphql/schema/build_from_definition.rb', line 814

def field_names
  @field_names
end

#instance_method_proc ⇒ Object (readonly)

Returns the value of attribute instance_method_proc.



819
820
821
# File 'lib/graphql/schema/build_from_definition.rb', line 819

def instance_method_proc
  @instance_method_proc
end

#method_names ⇒ Object (readonly)

Resolve method names by field name



817
818
819
# File 'lib/graphql/schema/build_from_definition.rb', line 817

def method_names
  @method_names
end

#singleton_method_proc ⇒ Object (readonly)

Returns the value of attribute singleton_method_proc.



819
820
821
# File 'lib/graphql/schema/build_from_definition.rb', line 819

def singleton_method_proc
  @singleton_method_proc
end