Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create.rb « environments « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 271585eb06c01e4f0020dbe65eb5035869bf3b9a (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

module Mutations
  module Environments
    class Create < ::Mutations::BaseMutation
      graphql_name 'EnvironmentCreate'
      description 'Create an environment.'

      include FindsProject

      authorize :create_environment

      argument :project_path,
        GraphQL::Types::ID,
        required: true,
        description: 'Full path of the project.'

      argument :name,
        GraphQL::Types::String,
        required: true,
        description: 'Name of the environment.'

      argument :external_url,
        GraphQL::Types::String,
        required: false,
        description: 'External URL of the environment.'

      argument :tier,
        Types::DeploymentTierEnum,
        required: false,
        description: 'Tier of the environment.'

      argument :cluster_agent_id,
        ::Types::GlobalIDType[::Clusters::Agent],
        required: false,
        description: 'Cluster agent of the environment.'

      field :environment,
        Types::EnvironmentType,
        null: true,
        description: 'Created environment.'

      def resolve(project_path:, **kwargs)
        project = authorized_find!(project_path)

        kwargs[:cluster_agent] = GitlabSchema.find_by_gid(kwargs.delete(:cluster_agent_id))&.sync

        response = ::Environments::CreateService.new(project, current_user, kwargs).execute

        if response.success?
          { environment: response.payload[:environment], errors: [] }
        else
          { environment: response.payload[:environment], errors: response.errors }
        end
      end
    end
  end
end