Class: Kanji::Type::MutationDefiner

Inherits:
Object
  • Object
show all
Extended by:
InstanceDefine
Defined in:
lib/kanji/type/mutation_definer.rb

Instance Method Summary collapse

Methods included from InstanceDefine

instance_define

Constructor Details

#initialize(&block) ⇒ MutationDefiner

Returns a new instance of MutationDefiner.

Raises:



13
14
15
16
17
18
19
20
21
# File 'lib/kanji/type/mutation_definer.rb', line 13

def initialize(&block)
  @_arguments = []
  self.instance_eval &block

  raise(AttributeError, "You must supply a name") unless @_name
  raise(AttributeError, "You must supply a return type") unless @_return_type
  raise(AttributeError, "You must supply a resolve proc") unless @_resolve
  raise(AttributeError, "You must supply at least one argument") if @_arguments.empty?
end

Instance Method Details

#argument(name, type, **kwargs) ⇒ Object

Raises:



23
24
25
26
27
28
29
30
31
# File 'lib/kanji/type/mutation_definer.rb', line 23

def argument(name, type, **kwargs)
  raise ArgumentError if @_arguments.map(&:name).include?(name.to_s)

  @_arguments << Argument.new({
    name: name.to_s,
    type: type,
    options: kwargs
  })
end

#callObject



33
34
35
36
37
38
39
40
# File 'lib/kanji/type/mutation_definer.rb', line 33

def call
  Mutation.new({
    name: @_name,
    return_type: @_return_type,
    arguments: @_arguments,
    resolve: @_resolve
  })
end