Class: Gitlab::Graphql::Present::FieldExtension

Inherits:
GraphQL::Schema::FieldExtension
  • Object
show all
Defined in:
lib/gitlab/graphql/present/field_extension.rb

Constant Summary collapse

SAFE_CONTEXT_KEYS =
%i[current_user].freeze

Instance Method Summary collapse

Instance Method Details

#resolve(object:, arguments:, context:) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/graphql/present/field_extension.rb', line 9

def resolve(object:, arguments:, context:)
  attrs = safe_context_values(context)

  # We need to handle the object being either a Schema::Object or an
  # inner Schema::Object#object. This depends on whether the field
  # has a @resolver_proc or not.
  if object.is_a?(::Types::BaseObject)
    type = field.owner.kind.abstract? ? object.class : field.owner
    object.present(type, attrs)
    yield(object, arguments)
  else
    # This is the legacy code-path, hit if the field has a @resolver_proc
    # TODO: remove this when resolve procs are removed from the
    # graphql-ruby library, and all field instrumentation is removed.
    # See: https://github.com/rmosolgo/graphql-ruby/issues/3385
    # See: https://gitlab.com/gitlab-org/gitlab/-/issues/363131
    presented = field.owner.try(:present, object, attrs) || object
    yield(presented, arguments)
  end
end