Skip to content
代码片段 群组 项目
未验证 提交 9c0dfedd 编辑于 作者: Heinrich Lee Yu's avatar Heinrich Lee Yu
浏览文件

Restore old behavior of resolve_type

We can't just call super because that just raises an exception. Since we
already have the accepts logic here, we just need to return the type if
it is part of the accepted types.
上级 794ad456
No related branches found
No related tags found
无相关合并请求
......@@ -79,7 +79,11 @@ def object_from_id(global_id, ctx = {})
def resolve_type(type, object, ctx = :__undefined__)
return if type.respond_to?(:assignable?) && !type.assignable?(object)
super
if type.kind.object?
type
else
super
end
end
# Find an object by looking it up from its 'GlobalID'.
......
......@@ -196,6 +196,39 @@ def initialize(id)
end
end
describe '.resolve_type' do
let(:object) { build(:user) }
let(:object_type) { Class.new(Types::BaseObject) }
let(:union_type) { Class.new(Types::BaseUnion) }
it 'returns the type for object types' do
expect(described_class.resolve_type(object_type, object, {})).to eq([object_type, object])
end
it 'raises an exception for non-object types' do
expect { described_class.resolve_type(union_type, object, {}) }.to raise_error(GraphQL::RequiredImplementationMissingError)
end
context 'when accepts is defined' do
let(:object_type) do
Class.new(Types::BaseObject) do
accepts User
end
end
it 'returns the type if the object is accepted' do
expect(described_class.resolve_type(object_type, object, {})).to eq([object_type, object])
end
it 'returns nil when object is not accepted' do
project = build(:project)
expect(described_class.resolve_type(object_type, project, {})).to eq([nil, project])
end
end
end
describe 'validate_max_errors' do
it 'reports at most 5 errors' do
query = <<~GQL
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册