Commit 99dd3edc authored by Alex Kalderimis's avatar Alex Kalderimis Committed by Alex Kalderimis

Design-Management: use GlobalID scalar

This uses the new GlobalID type in our GraphQL code. The benefits of
this are that we move validation about static data to outer edges of the
system, can remove validation code, and gain assurance about the IDs we
accept in our system.
parent c7cdd60c
...@@ -9,7 +9,7 @@ module Resolvers ...@@ -9,7 +9,7 @@ module Resolvers
authorize :read_design authorize :read_design
argument :id, GraphQL::ID_TYPE, argument :id, ::Types::GlobalIDType[::DesignManagement::DesignAtVersion],
required: true, required: true,
description: 'The Global ID of the design at this version' description: 'The Global ID of the design at this version'
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module Resolvers module Resolvers
module DesignManagement module DesignManagement
class DesignResolver < BaseResolver class DesignResolver < BaseResolver
argument :id, GraphQL::ID_TYPE, argument :id, ::Types::GlobalIDType[::DesignManagement::Design],
required: false, required: false,
description: 'Find a design by its ID' description: 'Find a design by its ID'
......
...@@ -4,15 +4,14 @@ module Resolvers ...@@ -4,15 +4,14 @@ module Resolvers
module DesignManagement module DesignManagement
class DesignsResolver < BaseResolver class DesignsResolver < BaseResolver
argument :ids, argument :ids,
[GraphQL::ID_TYPE], [::Types::GlobalIDType[::DesignManagement::Design]],
required: false, required: false,
description: 'Filters designs by their ID' description: 'Filters designs by their ID'
argument :filenames, argument :filenames,
[GraphQL::STRING_TYPE], [GraphQL::STRING_TYPE],
required: false, required: false,
description: 'Filters designs by their filename' description: 'Filters designs by their filename'
argument :at_version, argument :at_version, ::Types::GlobalIDType[::DesignManagement::Version],
GraphQL::ID_TYPE,
required: false, required: false,
description: 'Filters designs to only those that existed at the version. ' \ description: 'Filters designs to only those that existed at the version. ' \
'If argument is omitted or nil then all designs will reflect the latest version' 'If argument is omitted or nil then all designs will reflect the latest version'
...@@ -39,8 +38,8 @@ module Resolvers ...@@ -39,8 +38,8 @@ module Resolvers
GitlabSchema.object_from_id(at_version, expected_type: ::DesignManagement::Version)&.sync GitlabSchema.object_from_id(at_version, expected_type: ::DesignManagement::Version)&.sync
end end
def design_ids(ids) def design_ids(gids)
ids&.map { |id| GlobalID.parse(id, expected_type: ::DesignManagement::Design).model_id } Array.wrap(gids).compact.map(&:model_id).presence
end end
def issue def issue
......
...@@ -11,11 +11,11 @@ module Resolvers ...@@ -11,11 +11,11 @@ module Resolvers
authorize :read_design authorize :read_design
argument :id, GraphQL::ID_TYPE, argument :id, ::Types::GlobalIDType[::DesignManagement::DesignAtVersion],
required: false, required: false,
as: :design_at_version_id, as: :design_at_version_id,
description: 'The ID of the DesignAtVersion' description: 'The ID of the DesignAtVersion'
argument :design_id, GraphQL::ID_TYPE, argument :design_id, ::Types::GlobalIDType[::DesignManagement::Design],
required: false, required: false,
description: 'The ID of a specific design' description: 'The ID of a specific design'
argument :filename, GraphQL::STRING_TYPE, argument :filename, GraphQL::STRING_TYPE,
......
...@@ -11,8 +11,7 @@ module Resolvers ...@@ -11,8 +11,7 @@ module Resolvers
authorize :read_design authorize :read_design
argument :ids, argument :ids, [::Types::GlobalIDType[::DesignManagement::Design]],
[GraphQL::ID_TYPE],
required: false, required: false,
description: 'Filters designs by their ID' description: 'Filters designs by their ID'
argument :filenames, argument :filenames,
......
...@@ -14,7 +14,7 @@ module Resolvers ...@@ -14,7 +14,7 @@ module Resolvers
argument :sha, GraphQL::STRING_TYPE, argument :sha, GraphQL::STRING_TYPE,
required: false, required: false,
description: "The SHA256 of a specific version" description: "The SHA256 of a specific version"
argument :id, GraphQL::ID_TYPE, argument :id, ::Types::GlobalIDType[::DesignManagement::Version],
required: false, required: false,
description: 'The Global ID of the version' description: 'The Global ID of the version'
......
...@@ -9,7 +9,7 @@ module Resolvers ...@@ -9,7 +9,7 @@ module Resolvers
authorize :read_design authorize :read_design
argument :id, GraphQL::ID_TYPE, argument :id, ::Types::GlobalIDType[::DesignManagement::Version],
required: true, required: true,
description: 'The Global ID of the version' description: 'The Global ID of the version'
......
...@@ -12,7 +12,8 @@ module Resolvers ...@@ -12,7 +12,8 @@ module Resolvers
required: false, required: false,
description: 'The SHA256 of the most recent acceptable version' description: 'The SHA256 of the most recent acceptable version'
argument :earlier_or_equal_to_id, GraphQL::ID_TYPE, argument :earlier_or_equal_to_id,
::Types::GlobalIDType[::DesignManagement::Version],
as: :id, as: :id,
required: false, required: false,
description: 'The Global ID of the most recent acceptable version' description: 'The Global ID of the most recent acceptable version'
......
...@@ -63,6 +63,14 @@ RSpec.describe Resolvers::DesignManagement::DesignResolver do ...@@ -63,6 +63,14 @@ RSpec.describe Resolvers::DesignManagement::DesignResolver do
expect(resolve_design).to be_nil expect(resolve_design).to be_nil
end end
end end
context 'the ID does not belong to a design at all' do
let(:args) { { id: GitlabSchema.id_from_object(create(:user)).to_s } }
it 'complains meaningfully' do
expect { resolve_design }.to raise_error(::Gitlab::Graphql::Errors::ArgumentError, /not a valid id for DesignManagement::Design/)
end
end
end end
context 'by filename' do context 'by filename' do
......
...@@ -66,7 +66,7 @@ RSpec.describe Resolvers::DesignManagement::DesignsResolver do ...@@ -66,7 +66,7 @@ RSpec.describe Resolvers::DesignManagement::DesignsResolver do
let(:second_design) { create(:design, issue: issue, versions: [second_version]) } let(:second_design) { create(:design, issue: issue, versions: [second_version]) }
context 'the ID is on the current issue' do context 'the ID is on the current issue' do
let(:args) { { ids: [GitlabSchema.id_from_object(second_design).to_s] } } let(:args) { { ids: [GitlabSchema.id_from_object(second_design)] } }
it 'resolves to just the relevant design' do it 'resolves to just the relevant design' do
expect(resolve_designs).to contain_exactly(second_design) expect(resolve_designs).to contain_exactly(second_design)
...@@ -77,7 +77,7 @@ RSpec.describe Resolvers::DesignManagement::DesignsResolver do ...@@ -77,7 +77,7 @@ RSpec.describe Resolvers::DesignManagement::DesignsResolver do
let(:third_version) { create(:design_version) } let(:third_version) { create(:design_version) }
let(:third_design) { create(:design, issue: create(:issue, project: project), versions: [third_version]) } let(:third_design) { create(:design, issue: create(:issue, project: project), versions: [third_version]) }
let(:args) { { ids: [GitlabSchema.id_from_object(third_design).to_s] } } let(:args) { { ids: [GitlabSchema.id_from_object(third_design)] } }
it 'ignores it' do it 'ignores it' do
expect(resolve_designs).to be_empty expect(resolve_designs).to be_empty
......
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