summaryrefslogtreecommitdiff
path: root/app/graphql/resolvers/package_details_resolver.rb
blob: 42cb23e701db7a74773414f3a034e704488319bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

module Resolvers
  class PackageDetailsResolver < BaseResolver
    type ::Types::Packages::PackageDetailsType, null: true

    argument :id, ::Types::GlobalIDType[::Packages::Package],
      required: true,
      description: 'Global ID of the package.'

    def ready?(**args)
      context[self.class] ||= { executions: 0 }
      context[self.class][:executions] += 1
      raise GraphQL::ExecutionError, "Package details can be requested only for one package at a time" if context[self.class][:executions] > 1

      super
    end

    def resolve(id:)
      # TODO: remove this line when the compatibility layer is removed
      # See: https://gitlab.com/gitlab-org/gitlab/-/issues/257883
      id = ::Types::GlobalIDType[::Packages::Package].coerce_isolated_input(id)
      GitlabSchema.find_by_gid(id)
    end
  end
end