Class: Mutations::JobInvocations::Create
- Inherits:
-
CreateMutation
- Object
- CreateMutation
- Mutations::JobInvocations::Create
- Defined in:
- app/graphql/mutations/job_invocations/create.rb
Instance Method Summary collapse
- #map_all_errors(job_invocation) ⇒ Object
- #map_errors(attr_name, resource) ⇒ Object
- #resolve(params) ⇒ Object
Instance Method Details
#map_all_errors(job_invocation) ⇒ Object
29 30 31 |
# File 'app/graphql/mutations/job_invocations/create.rb', line 29 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 |
#map_errors(attr_name, resource) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'app/graphql/mutations/job_invocations/create.rb', line 33 def map_errors(attr_name, resource) resource.errors.map do |attribute, | { path: [attr_name, attribute.to_s.camelize(:lower)], message: , } end end |
#resolve(params) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/graphql/mutations/job_invocations/create.rb', line 10 def resolve(params) begin composer = JobInvocationComposer.from_api_params(params[:job_invocation].to_h) job_invocation = composer.job_invocation (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. }] end { result_key => job_invocation, :errors => errors, } end |