Class: GraphQL::Directive

Inherits:
ObjectType show all
Defined in:
lib/graph_ql/directive.rb

Constant Summary collapse

LOCATIONS =
[
  ON_OPERATION =  :on_operation?,
  ON_FRAGMENT =   :on_fragment?,
  ON_FIELD =      :on_field?,
]

Instance Method Summary collapse

Methods inherited from ObjectType

#arg, #field, #fields, #fields=, #interfaces, #kind, #to_s, #type

Methods included from Definable

#attr_definable

Methods included from NonNullWithBang

#!

Constructor Details

#initialize {|_self| ... } ⇒ Directive

Returns a new instance of Directive.

Yields:

  • (_self)

Yield Parameters:



13
14
15
16
17
# File 'lib/graph_ql/directive.rb', line 13

def initialize(&block)
  @arguments = {}
  @on = []
  yield(self) if block_given?
end

Instance Method Details

#arguments(new_arguments = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/graph_ql/directive.rb', line 27

def arguments(new_arguments=nil)
  if new_arguments.nil?
    @arguments
  else
    @arguments = new_arguments
      .reduce({}) {|memo, (k, v)| memo[k.to_s] = v; memo}
      .each { |k, v| v.respond_to?("name=") && v.name = k}
  end
end

#resolve(proc_or_arguments, proc = nil) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/graph_ql/directive.rb', line 19

def resolve(proc_or_arguments, proc=nil)
  if proc.nil?
    @resolve_proc = proc_or_arguments
  else
    @resolve_proc.call(proc_or_arguments, proc)
  end
end