Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/graphql/present/field_extension_spec.rb')
-rw-r--r--spec/lib/gitlab/graphql/present/field_extension_spec.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/lib/gitlab/graphql/present/field_extension_spec.rb b/spec/lib/gitlab/graphql/present/field_extension_spec.rb
index 5e66e16d655..6ea313d30b3 100644
--- a/spec/lib/gitlab/graphql/present/field_extension_spec.rb
+++ b/spec/lib/gitlab/graphql/present/field_extension_spec.rb
@@ -33,6 +33,48 @@ RSpec.describe Gitlab::Graphql::Present::FieldExtension do
end
end
+ context 'when the field is declared on an interface, and implemented by a presenter' do
+ let(:interface) do
+ Module.new do
+ include ::Types::BaseInterface
+
+ field :interface_field, GraphQL::STRING_TYPE, null: true
+ end
+ end
+
+ let(:implementation) do
+ type = fresh_object_type('Concrete')
+ type.present_using(concrete_impl)
+ type.implements(interface)
+ type
+ end
+
+ def concrete_impl
+ Class.new(base_presenter) do
+ def interface_field
+ 'made of concrete'
+ end
+ end
+ end
+
+ it 'resolves the interface field using the implementation from the presenter' do
+ field = ::Types::BaseField.new(name: :interface_field, type: GraphQL::STRING_TYPE, null: true, owner: interface)
+ value = resolve_field(field, object, object_type: implementation)
+
+ expect(value).to eq 'made of concrete'
+ 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
+
describe 'interactions with inheritance' do
def parent
type = fresh_object_type('Parent')