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
authorize :read_design
argument :id, GraphQL::ID_TYPE,
argument :id, ::Types::GlobalIDType[::DesignManagement::DesignAtVersion],
required: true,
description: 'The Global ID of the design at this version'
......
......@@ -3,7 +3,7 @@
module Resolvers
module DesignManagement
class DesignResolver < BaseResolver
argument :id, GraphQL::ID_TYPE,
argument :id, ::Types::GlobalIDType[::DesignManagement::Design],
required: false,
description: 'Find a design by its ID'
......
......@@ -4,15 +4,14 @@ module Resolvers
module DesignManagement
class DesignsResolver < BaseResolver
argument :ids,
[GraphQL::ID_TYPE],
[::Types::GlobalIDType[::DesignManagement::Design]],
required: false,
description: 'Filters designs by their ID'
argument :filenames,
[GraphQL::STRING_TYPE],
required: false,
description: 'Filters designs by their filename'
argument :at_version,
GraphQL::ID_TYPE,
argument :at_version, ::Types::GlobalIDType[::DesignManagement::Version],
required: false,
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'
......@@ -39,8 +38,8 @@ module Resolvers
GitlabSchema.object_from_id(at_version, expected_type: ::DesignManagement::Version)&.sync
end
def design_ids(ids)
ids&.map { |id| GlobalID.parse(id, expected_type: ::DesignManagement::Design).model_id }
def design_ids(gids)
Array.wrap(gids).compact.map(&:model_id).presence
end
def issue
......
......@@ -11,11 +11,11 @@ module Resolvers
authorize :read_design
argument :id, GraphQL::ID_TYPE,
argument :id, ::Types::GlobalIDType[::DesignManagement::DesignAtVersion],
required: false,
as: :design_at_version_id,
description: 'The ID of the DesignAtVersion'
argument :design_id, GraphQL::ID_TYPE,
argument :design_id, ::Types::GlobalIDType[::DesignManagement::Design],
required: false,
description: 'The ID of a specific design'
argument :filename, GraphQL::STRING_TYPE,
......
......@@ -11,8 +11,7 @@ module Resolvers
authorize :read_design
argument :ids,
[GraphQL::ID_TYPE],
argument :ids, [::Types::GlobalIDType[::DesignManagement::Design]],
required: false,
description: 'Filters designs by their ID'
argument :filenames,
......
......@@ -14,7 +14,7 @@ module Resolvers
argument :sha, GraphQL::STRING_TYPE,
required: false,
description: "The SHA256 of a specific version"
argument :id, GraphQL::ID_TYPE,
argument :id, ::Types::GlobalIDType[::DesignManagement::Version],
required: false,
description: 'The Global ID of the version'
......
......@@ -9,7 +9,7 @@ module Resolvers
authorize :read_design
argument :id, GraphQL::ID_TYPE,
argument :id, ::Types::GlobalIDType[::DesignManagement::Version],
required: true,
description: 'The Global ID of the version'
......
......@@ -12,7 +12,8 @@ module Resolvers
required: false,
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,
required: false,
description: 'The Global ID of the most recent acceptable version'
......
......@@ -63,6 +63,14 @@ RSpec.describe Resolvers::DesignManagement::DesignResolver do
expect(resolve_design).to be_nil
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
context 'by filename' do
......
......@@ -66,7 +66,7 @@ RSpec.describe Resolvers::DesignManagement::DesignsResolver do
let(:second_design) { create(:design, issue: issue, versions: [second_version]) }
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
expect(resolve_designs).to contain_exactly(second_design)
......@@ -77,7 +77,7 @@ RSpec.describe Resolvers::DesignManagement::DesignsResolver do
let(:third_version) { create(:design_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
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