Class: Hai::GraphQL::DeleteMutations

Inherits:
Object
  • Object
show all
Defined in:
lib/hai/graphql/delete_mutations.rb

Class Method Summary collapse

Class Method Details

.add(mutation_type, model) ⇒ Object



5
6
7
8
# File 'lib/hai/graphql/delete_mutations.rb', line 5

def add(mutation_type, model)
  add_field(mutation_type, model)
  define_create_method(mutation_type, model)
end

.add_field(mutation_type, model) ⇒ Object



10
11
12
13
14
15
# File 'lib/hai/graphql/delete_mutations.rb', line 10

def add_field(mutation_type, model)
  mutation_type.field("delete_#{model.name.downcase}", "Types::#{model}Type".constantize) do
    mutation_type.description("Delete a #{model}.")
    argument(:id, ::GraphQL::Types::ID)
  end
end

.define_create_method(mutation_type, model) ⇒ Object



17
18
19
20
21
# File 'lib/hai/graphql/delete_mutations.rb', line 17

def define_create_method(mutation_type, model)
  mutation_type.define_method("delete_#{model.name.downcase}") do |id:|
    Hai::Delete.new(model, context).execute(id: id)
  end
end