1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
# frozen_string_literal: true
<% module_namespacing_when_supported do -%>
module Mutations
class <%= class_name %>Create < BaseMutation
description "Creates a new <%= file_name %>"
field :<%= file_name %>, Types::<%= options[:namespaced_types] ? 'Objects::' : '' %><%= class_name %>Type, null: false
argument :<%= file_name %>_input, Types::<%= options[:namespaced_types] ? 'Inputs::' : '' %><%= class_name %>InputType, required: true
def resolve(<%= file_name %>_input:)
<%= singular_table_name %> = ::<%= orm_class.build(class_name, "**#{file_name}_input") %>
raise GraphQL::ExecutionError.new "Error creating <%= file_name %>", extensions: <%= singular_table_name %>.errors.to_hash unless <%= orm_instance.save %>
{ <%= file_name %>: <%= singular_table_name %> }
end
end
end
<% end -%>
|