Class: GraphQL::ObjectType

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

Overview

This type exposes fields on an object.

Defined Under Namespace

Classes: Printer

Instance Method Summary collapse

Methods included from DefinitionHelpers::Definable

attr_definable

Methods included from DefinitionHelpers::NonNullWithBang

#!

Constructor Details

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

Returns a new instance of ObjectType.

Yields:

Yield Parameters:



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

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

Instance Method Details

#==(other) ⇒ Boolean

Returns are these types equivalent? (incl. non-null, list).

Parameters:

Returns:

  • (Boolean)

    are these types equivalent? (incl. non-null, list)



71
72
73
74
75
76
77
# File 'lib/graph_ql/object_type.rb', line 71

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

#fields(new_fields) ⇒ Object #fieldsHash

Overloads:

  • #fields(new_fields) ⇒ Object

    Define ‘new_fields` as the fields this type exposes, uses #fields=

  • #fieldsHash

    Returns fields this type exposes.

    Returns:

    • (Hash)

      fields this type exposes



25
26
27
28
29
30
# File 'lib/graph_ql/object_type.rb', line 25

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

#fields=(new_fields) ⇒ Object

Define fields to be ‘new_fields`, normalize with StringNamedHash

Parameters:

  • new_fields (Hash)

    The fields exposed by this type



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

def fields=(new_fields)
  @fields = GraphQL::DefinitionHelpers::StringNamedHash.new(new_fields).to_h
end

#interfaces(new_interfaces) ⇒ Object #interfacesArray<GraphQL::Interface>

Overloads:

  • #interfaces(new_interfaces) ⇒ Object

    Declare that this type implements ‘new_interfaces`. Shovel this type into each interface’s ‘possible_types` array.

    (There’s a bug here: if you define interfaces twice, it won’t remove previous definitions.)

    Parameters:

    • new_interfaces (Array<GraphQL::Interface>)

      interfaces that this type implements

  • #interfacesArray<GraphQL::Interface>

    Returns interfaces that this type implements.

    Returns:

    • (Array<GraphQL::Interface>)

      interfaces that this type implements



50
51
52
53
54
55
56
# File 'lib/graph_ql/object_type.rb', line 50

def interfaces(new_interfaces=nil)
  if !new_interfaces.nil?
    @interfaces = new_interfaces
    new_interfaces.each {|i| i.possible_types << self }
  end
  @interfaces
end

#kindObject



58
59
60
# File 'lib/graph_ql/object_type.rb', line 58

def kind
  GraphQL::TypeKinds::OBJECT
end

#to_sObject Also known as: inspect

Print the human-readable name of this type



63
64
65
# File 'lib/graph_ql/object_type.rb', line 63

def to_s
  Printer.instance.print(self)
end