Module: GraphitiGraphQL::Federation::EntitiesFieldOverride

Defined in:
lib/graphiti_graphql/federation/apollo_federation_override.rb

Instance Method Summary collapse

Instance Method Details

#_entities(representations:, lookahead:) ⇒ Object

accept the lookahead as argument



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/graphiti_graphql/federation/apollo_federation_override.rb', line 21

def _entities(representations:, lookahead:)
  representations.map do |reference|
    typename = reference[:__typename]
    type = context.warden.get_type(typename)
    if type.nil? || type.kind != GraphQL::TypeKinds::OBJECT
      raise "The _entities resolver tried to load an entity for type \"#{typename}\"," \
            " but no object type of that name was found in the schema"
    end

    type_class = type.is_a?(GraphQL::ObjectType) ? type.[:type_class] : type
    if type_class.respond_to?(:resolve_reference)
      meth = type_class.method(:resolve_reference)
      # ** THIS IS OUR EDIT **
      result = if meth.arity == 3
        type_class.resolve_reference(reference, context, lookahead)
      else
        type_class.resolve_reference(reference, context)
      end
    else
      result = reference
    end

    context.schema.after_lazy(result) do |resolved_value|
      context[resolved_value] = type
      resolved_value
    end
  end
end