Commit 4dc64fe5 authored by Alex Kalderimis's avatar Alex Kalderimis

Provide a default implementation of resolve_type

This makes use of loads a bit safer.
parent 6d32c609
...@@ -8,6 +8,12 @@ module Types ...@@ -8,6 +8,12 @@ module Types
field_class Types::BaseField field_class Types::BaseField
def self.accepts(*types)
@accepts ||= []
@accepts += types
@accepts
end
# All graphql fields exposing an id, should expose a global id. # All graphql fields exposing an id, should expose a global id.
def id def id
GitlabSchema.id_from_object(object) GitlabSchema.id_from_object(object)
...@@ -16,5 +22,13 @@ module Types ...@@ -16,5 +22,13 @@ module Types
def current_user def current_user
context[:current_user] context[:current_user]
end end
def self.resolve_type(object, context)
assignable = accepts
return self if assignable.blank?
self if assignable.any? { |cls| object.is_a?(cls) }
end
end end
end end
...@@ -4,7 +4,7 @@ module Types ...@@ -4,7 +4,7 @@ module Types
class BoardType < BaseObject class BoardType < BaseObject
graphql_name 'Board' graphql_name 'Board'
description 'Represents a project or group board' description 'Represents a project or group board'
accepts ::Board
authorize :read_board authorize :read_board
field :id, type: GraphQL::ID_TYPE, null: false, field :id, type: GraphQL::ID_TYPE, null: false,
......
...@@ -6,7 +6,7 @@ module Types ...@@ -6,7 +6,7 @@ module Types
graphql_name 'Epic' graphql_name 'Epic'
description 'Represents an epic' description 'Represents an epic'
accepts ::Epic
authorize :read_epic authorize :read_epic
expose_permissions Types::PermissionTypes::Epic expose_permissions Types::PermissionTypes::Epic
......
...@@ -64,6 +64,17 @@ RSpec.describe 'Update of an existing issue' do ...@@ -64,6 +64,17 @@ RSpec.describe 'Update of an existing issue' do
expect(graphql_errors).not_to be_blank expect(graphql_errors).not_to be_blank
end end
end end
context 'the epic is not an epic' do
let(:epic) { create(:user) }
it 'does not set the epic' do
post_graphql_mutation(mutation, current_user: current_user)
expect(response).to have_gitlab_http_status(:success)
expect(graphql_errors).not_to be_blank
end
end
end end
context 'removing epic' do context 'removing epic' 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