Sha256: 96cfa7de6d5332a7e551685c100fb182e404edd50d04dae5e38cd276de150c5d

Contents?: true

Size: 1.43 KB

Versions: 67

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

67 entries across 67 versions & 1 rubygems

Version Path
foreman_remote_execution-14.1.1 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-14.1.0 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-14.0.2 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-14.0.1 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-13.2.6 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-14.0.0 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-13.2.5 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-13.2.4 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-13.2.3 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-13.2.2 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-12.0.7 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-13.2.1 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-13.2.0 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-10.1.3 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-13.0.0 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-12.0.5 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-12.0.4 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-12.0.1 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-12.0.2 app/graphql/mutations/job_invocations/create.rb
foreman_remote_execution-11.1.3 app/graphql/mutations/job_invocations/create.rb