Class: GraphQL::ObjectType

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

Defined Under Namespace

Classes: Printer

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

#==(other) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/graph_ql/types/object_type.rb', line 46

def ==(other)
  if other.is_a?(GraphQL::ObjectType)
    self.to_s == other.to_s
  else
    super
  end
end

#fields(new_fields = nil) ⇒ Object



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

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

#fields=(new_fields) ⇒ Object



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

def fields=(new_fields)
  stringified_fields = GraphQL::StringNamedHash.new(new_fields).to_h
  # TODO: should this field be exposed during introspection? https://github.com/graphql/graphql-js/issues/73
  stringified_fields["__typename"] = GraphQL::Introspection::TypenameField.create(self)
  @fields = stringified_fields
end

#interfaces(new_interfaces = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/graph_ql/types/object_type.rb', line 26

def interfaces(new_interfaces=nil)
  if !new_interfaces.nil?
    # 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
  @interfaces
end

#kindObject



36
37
38
# File 'lib/graph_ql/types/object_type.rb', line 36

def kind
  GraphQL::TypeKinds::OBJECT
end

#to_sObject Also known as: inspect



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

def to_s
  Printer.instance.print(self)
end