diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-20 02:18:09 +0300 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /app/graphql/resolvers/deployments_resolver.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'app/graphql/resolvers/deployments_resolver.rb')
-rw-r--r-- | app/graphql/resolvers/deployments_resolver.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/app/graphql/resolvers/deployments_resolver.rb b/app/graphql/resolvers/deployments_resolver.rb new file mode 100644 index 00000000000..341d23c2ccb --- /dev/null +++ b/app/graphql/resolvers/deployments_resolver.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module Resolvers + class DeploymentsResolver < BaseResolver + argument :statuses, [Types::DeploymentStatusEnum], + description: 'Statuses of the deployments.', + required: false, + as: :status + + argument :order_by, Types::DeploymentsOrderByInputType, + description: 'Order by a specified field.', + required: false + + type Types::DeploymentType, null: true + + alias_method :environment, :object + + def resolve(**args) + return unless environment.present? && environment.is_a?(::Environment) + + args = transform_args_for_finder(**args) + + # GraphQL BatchLoader shouldn't be used here because pagination query will be inefficient + # that fetches thousands of rows before limiting and offsetting. + DeploymentsFinder.new(environment: environment.id, **args).execute + end + + private + + def transform_args_for_finder(**args) + if (order_by = args.delete(:order_by)) + order_by = order_by.to_h.map { |k, v| { order_by: k.to_s, sort: v } }.first + args.merge!(order_by) + end + + args + end + end +end |