Class: GraphQL::ObjectType

Inherits:
Object
  • Object
show all
Extended by:
Definable
Includes:
NonNullWithBang
Defined in:
lib/graph_ql/types/object_type.rb

Instance Method Summary collapse

Methods included from Definable

attr_definable

Methods included from NonNullWithBang

#!

Constructor Details

#initialize {|_self, GraphQL::TypeDefiner.instance, GraphQL::FieldDefiner.instance, GraphQL::ArgumentDefiner.instance| ... } ⇒ ObjectType

Returns a new instance of ObjectType.

Yields:

Yield Parameters:



6
7
8
9
10
# File 'lib/graph_ql/types/object_type.rb', line 6

def initialize(&block)
  self.fields = []
  self.interfaces = []
  yield(self, GraphQL::TypeDefiner.instance, GraphQL::FieldDefiner.instance, GraphQL::ArgumentDefiner.instance)
end

Instance Method Details

#fields(new_fields = nil) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/graph_ql/types/object_type.rb', line 12

def fields(new_fields=nil)
  if new_fields
    self.fields = new_fields
  else
    @fields
  end
end

#fields=(new_fields) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/graph_ql/types/object_type.rb', line 20

def fields=(new_fields)
  stringified_fields = new_fields
    .reduce({}) { |memo, (key, value)| memo[key.to_s] = value; memo }
  # Set the name from its context on this type:
  stringified_fields.each {|k, v| v.respond_to?("name=") && v.name = k }
  stringified_fields["__typename"] = GraphQL::Introspection::TypenameField.create(self)
  @fields = stringified_fields
end

#inspectObject



48
49
50
# File 'lib/graph_ql/types/object_type.rb', line 48

def inspect
  to_s
end

#interfaces(new_interfaces = nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/graph_ql/types/object_type.rb', line 29

def interfaces(new_interfaces=nil)
  if new_interfaces.nil?
    @interfaces
  else
    # if you define interfaces twice, you're gonna have a bad time :(
    # (because it gets registered with that interface, then overriden)
    @interfaces = new_interfaces
    new_interfaces.each {|i| i.possible_types << self }
  end
end

#kindObject



40
41
42
# File 'lib/graph_ql/types/object_type.rb', line 40

def kind
  GraphQL::TypeKinds::OBJECT
end

#to_sObject



44
45
46
# File 'lib/graph_ql/types/object_type.rb', line 44

def to_s
  "<GraphQL::ObjectType #{name}>"
end