Commit dd6330e8 authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'ajk-fix-merge-requests-assignees-web-url' into 'master'

Take inheritance into account when presenting fields

See merge request gitlab-org/gitlab!60428
parents 019fecec 20b17704
---
title: Fix regression in GraphQL field MergeRequest.assignees.webUrl
merge_request: 60428
author:
type: fixed
...@@ -10,14 +10,14 @@ module Gitlab ...@@ -10,14 +10,14 @@ module Gitlab
end end
def self.presenter_class def self.presenter_class
@presenter_class @presenter_class || superclass.try(:presenter_class)
end end
def self.present(object, attrs) def self.present(object, attrs)
klass = @presenter_class klass = presenter_class
return object if !klass || object.is_a?(klass) return object if !klass || object.is_a?(klass)
@presenter_class.new(object, **attrs) klass.new(object, **attrs)
end end
end end
......
...@@ -63,6 +63,16 @@ RSpec.describe Gitlab::Graphql::Present::FieldExtension do ...@@ -63,6 +63,16 @@ RSpec.describe Gitlab::Graphql::Present::FieldExtension do
expect(value).to eq 'made of concrete' expect(value).to eq 'made of concrete'
end end
context 'when the implementation is inherited' do
it 'resolves the interface field using the implementation from the presenter' do
subclass = Class.new(implementation) { graphql_name 'Subclass' }
field = ::Types::BaseField.new(name: :interface_field, type: GraphQL::STRING_TYPE, null: true, owner: interface)
value = resolve_field(field, object, object_type: subclass)
expect(value).to eq 'made of concrete'
end
end
end end
describe 'interactions with inheritance' do describe 'interactions with inheritance' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment