debian-mirror-gitlab/app/graphql/resolvers/design_management/design_resolver.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
1.4 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
module Resolvers
module DesignManagement
class DesignResolver < BaseResolver
2021-01-29 00:20:46 +05:30
type ::Types::DesignManagement::DesignType, null: true
2021-02-22 17:27:13 +05:30
requires_argument!
2021-01-29 00:20:46 +05:30
argument :id, ::Types::GlobalIDType[::DesignManagement::Design],
2020-05-24 23:13:21 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Find a design by its ID.'
2020-05-24 23:13:21 +05:30
2021-10-27 15:23:28 +05:30
argument :filename, GraphQL::Types::String,
2020-05-24 23:13:21 +05:30
required: false,
2021-03-08 18:12:59 +05:30
description: 'Find a design by its filename.'
2020-05-24 23:13:21 +05:30
def resolve(filename: nil, id: nil)
params = parse_args(filename, id)
build_finder(params).execute.first
end
def self.single
self
end
private
def issue
object.issue
end
def build_finder(params)
::DesignManagement::DesignsFinder.new(issue, current_user, params)
end
def error(msg)
raise ::Gitlab::Graphql::Errors::ArgumentError, msg
end
def parse_args(filename, id)
provided = [filename, id].map(&:present?)
if provided.none?
error('one of id or filename must be passed')
elsif provided.all?
error('only one of id or filename may be passed')
elsif filename.present?
{ filenames: [filename] }
else
{ ids: [parse_gid(id)] }
end
end
def parse_gid(gid)
2021-01-29 00:20:46 +05:30
gid.model_id
2020-05-24 23:13:21 +05:30
end
end
end
end