Class: GraphQL::ObjectType

Inherits:
BaseType show all
Defined in:
lib/graphql/object_type.rb

Instance Attribute Summary collapse

Attributes inherited from BaseType

#ast_node, #default_relay, #default_scalar, #description, #introspection, #name

Instance Method Summary collapse

Methods inherited from BaseType

#==, #coerce_input, #coerce_isolated_input, #coerce_isolated_result, #coerce_result, #default_relay?, #default_scalar?, #introspection?, #list?, #non_null?, resolve_related_type, #resolve_type, #to_definition, #to_list_type, #to_non_null_type, #to_s, #type_class, #unwrap, #valid_input?, #valid_isolated_input?, #validate_input, #validate_isolated_input

Methods included from Relay::TypeExtensions

#connection_type, #define_connection, #define_edge, #edge_type

Methods included from Define::InstanceDefinable

#define, #metadata, #redefine

Methods included from Define::NonNullWithBang

#!

Constructor Details

#initializeObjectType

Returns a new instance of ObjectType.



17
18
19
20
21
22
23
# File 'lib/graphql/object_type.rb', line 17

def initialize
  super
  @fields = {}
  @interface_fields = {}
  @dirty_interfaces = []
  @dirty_inherited_interfaces = []
end

Instance Attribute Details

#fieldsHash<String => GraphQL::Field>

Returns Map String fieldnames to their Field implementations.

Returns:



11
12
13
# File 'lib/graphql/object_type.rb', line 11

def fields
  @fields
end

#mutationGraphQL::Relay::Mutation?

Returns The mutation this object type was derived from, if it is an auto-generated payload type.

Returns:

  • (GraphQL::Relay::Mutation, nil)

    The mutation this object type was derived from, if it is an auto-generated payload type.



17
18
19
# File 'lib/graphql/object_type.rb', line 17

def mutation
  @mutation
end

#relay_node_typeObject



8
9
10
# File 'lib/graphql/object_type.rb', line 8

def relay_node_type
  @relay_node_type
end

Instance Method Details

#all_fieldsArray<GraphQL::Field>

These fields don’t have instrumenation applied

Returns:

  • (Array<GraphQL::Field>)

    All fields, including ones inherited from interfaces

See Also:

  • Get fields with instrumentation


66
67
68
# File 'lib/graphql/object_type.rb', line 66

def all_fields
  interface_fields.merge(self.fields).values
end

#get_field(field_name) ⇒ GraphQL::Field

This fields doesnt have instrumenation applied

Returns:

  • (GraphQL::Field)

    The field definition for field_name (may be inherited from interfaces)

See Also:

  • Get field with instrumentation


59
60
61
# File 'lib/graphql/object_type.rb', line 59

def get_field(field_name)
  fields[field_name] || interface_fields[field_name]
end

#implements(interfaces, inherit: false) ⇒ Object

Declare that this object implements this interface. This declaration will be validated when the schema is defined.

Parameters:

  • interfaces (Array<GraphQL::Interface>)

    add a new interface that this type implements

  • inherits (Boolean)

    If true, copy the interfaces’ field definitions to this type



74
75
76
77
78
79
80
81
82
83
# File 'lib/graphql/object_type.rb', line 74

def implements(interfaces, inherit: false)
  if !interfaces.is_a?(Array)
    raise ArgumentError, "`implements(interfaces)` must be an array, not #{interfaces.class} (#{interfaces})"
  end

  @clean_interfaces = nil
  @clean_inherited_fields = nil
  dirty_ifaces = inherit ? @dirty_inherited_interfaces : @dirty_interfaces
  dirty_ifaces.concat(interfaces)
end

#initialize_copy(other) ⇒ Object



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

def initialize_copy(other)
  super
  @clean_interfaces = nil
  @clean_inherited_interfaces = nil
  @dirty_interfaces = other.dirty_interfaces.dup
  @dirty_inherited_interfaces = other.dirty_inherited_interfaces.dup
  @fields = other.fields.dup
end

#interfacesObject



47
48
49
50
# File 'lib/graphql/object_type.rb', line 47

def interfaces
  load_interfaces
  @clean_interfaces
end

#interfaces=(new_interfaces) ⇒ Object

Deprecated.

Use implements instead of interfaces.

This method declares interfaces for this type AND inherits any field definitions

Parameters:

  • new_interfaces (Array<GraphQL::Interface>)

    interfaces that this type implements



37
38
39
40
41
42
43
44
45
# File 'lib/graphql/object_type.rb', line 37

def interfaces=(new_interfaces)
  @clean_interfaces = nil
  @clean_inherited_interfaces = nil
  @clean_inherited_fields = nil

  @dirty_inherited_interfaces = []
  @dirty_inherited_fields = {}
  implements(new_interfaces, inherit: true)
end

#kindObject



52
53
54
# File 'lib/graphql/object_type.rb', line 52

def kind
  GraphQL::TypeKinds::OBJECT
end

#resolve_type_procObject



85
86
87
# File 'lib/graphql/object_type.rb', line 85

def resolve_type_proc
  nil
end