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