Commit a93248cd authored by charlie ablett's avatar charlie ablett

Merge branch 'bw-remove-accepts-definition' into 'master'

[graphql] Remove use of `accepts_definition` in graphql

See merge request gitlab-org/gitlab!84899
parents 0ea9c0a6 1e126638
......@@ -9,6 +9,13 @@ module Types
field_class Types::BaseField
edge_type_class Types::BaseEdge
def self.authorize(*args)
raise 'Cannot redefine authorize' if @authorize_args && args.any?
@authorize_args = args.freeze if args.any?
@authorize_args || (superclass.respond_to?(:authorize) ? superclass.authorize : nil)
end
def self.accepts(*types)
@accepts ||= []
@accepts += types
......
# frozen_string_literal: true
GraphQL::ObjectType.accepts_definitions(authorize: GraphQL::Define.assign_metadata_key(:authorize))
GraphQL::Schema::Object.accepts_definition(:authorize)
......@@ -428,5 +428,25 @@ RSpec.describe Types::BaseObject do
expect(result.dig('data', 'users', 'nodes'))
.to contain_exactly({ 'name' => active_users.first.name })
end
describe '.authorize' do
let_it_be(:read_only_type) do
Class.new(described_class) do
authorize :read_only
end
end
let_it_be(:inherited_read_only_type) { Class.new(read_only_type) }
it 'keeps track of the specified value' do
expect(described_class.authorize).to be_nil
expect(read_only_type.authorize).to match_array [:read_only]
expect(inherited_read_only_type.authorize).to match_array [:read_only]
end
it 'can not redefine the authorize value' do
expect { read_only_type.authorize(:write_only) }.to raise_error('Cannot redefine authorize')
end
end
end
end
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