Module: GraphQL::Define::MutationFields

Defined in:
lib/graphql/define/mutation_fields.rb

Overview

# Define MutableType by define block

Class Method Summary collapse

Class Method Details

.call(mutable_type, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/graphql/define/mutation_fields.rb', line 5

def self.call(mutable_type, &block)
  mutation_type = mutation_type(mutable_type, &block)

  mutable_type.fields['mutation'] = GraphQL::Field.define do
    name 'mutation'
    type mutation_type
    description mutation_type.description

    resolve -> (obj, _args, _cxt) { obj }
  end
end

.mutation_type(mutable_type, &block) ⇒ Object

define nested mutation type



20
21
22
23
24
25
# File 'lib/graphql/define/mutation_fields.rb', line 20

def self.mutation_type(mutable_type, &block)
  m_type = GraphQL::ObjectType.define(&block)
  m_type.name = "#{mutable_type.name}Mutation"
  m_type.description = "Mutations of #{mutable_type.description}"
  m_type
end