class Kanji::Type::MutationDefiner

Public Class Methods

new(&block) click to toggle source
# 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

Public Instance Methods

argument(name, type, **kwargs) click to toggle source
# 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
call() click to toggle source
# File lib/kanji/type/mutation_definer.rb, line 33
def call
  Mutation.new({
    name: @_name,
    return_type: @_return_type,
    arguments: @_arguments,
    resolve: @_resolve
  })
end