Sha256: 96cfa7de6d5332a7e551685c100fb182e404edd50d04dae5e38cd276de150c5d

Contents?: true

Size: 1.43 KB

Versions: 68

Compression:

Stored size: 1.43 KB

Contents

module Mutations
  module JobInvocations
    class Create < ::Mutations::CreateMutation
      description 'Create a new job invocation'
      graphql_name 'CreateJobInvocationMutation'

      argument :job_invocation, ::Types::JobInvocationInput, required: true
      field :job_invocation, ::Types::JobInvocation, 'The new job invocation', null: true

      def resolve(params)
        begin
          composer = JobInvocationComposer.from_api_params(params[:job_invocation].to_h)
          job_invocation = composer.job_invocation
          authorize!(job_invocation, :create)
          errors = []
          composer.trigger!
        rescue ActiveRecord::RecordNotSaved
          errors = map_all_errors(job_invocation)
        rescue JobInvocationComposer::JobTemplateNotFound, JobInvocationComposer::FeatureNotFound => e
          errors = [{ path => ['job_template'], :message => e.message }]
        end

        {
          result_key => job_invocation,
          :errors => errors,
        }
      end

      def map_all_errors(job_invocation)
        map_errors_to_path(job_invocation) + map_errors('triggering', job_invocation.triggering) + map_errors('targeting', job_invocation.targeting)
      end

      def map_errors(attr_name, resource)
        resource.errors.map do |attribute, message|
          {
            path: [attr_name, attribute.to_s.camelize(:lower)],
            message: message,
          }
        end
      end
    end
  end
end

Version data entries

68 entries across 68 versions & 1 rubygems

Version Path
foreman_remote_execution-9.1.0 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-8.2.1 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-8.2.0 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-9.0.1 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-9.0.0 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-8.1.2 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-8.1.1 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-8.1.0 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-7.2.2 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-7.2.1 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-7.2.0 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-5.0.8 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-8.0.0 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-7.1.1 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-7.1.0 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-7.0.0 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-5.0.7 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-5.0.6 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-6.2.0 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-5.0.5 app/graphql/mutations/job_invocations/create.rb