Class: GraphQL::Schema::Object Private

Inherits:
Member
  • Object
show all
Extended by:
Member::AcceptsDefinition, Member::HasFields
Defined in:
lib/graphql/schema/object.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Direct Known Subclasses

Introspection::BaseObject

Constant Summary

Constants included from Member::GraphQLTypeNames

Member::GraphQLTypeNames::Boolean, Member::GraphQLTypeNames::ID, Member::GraphQLTypeNames::Int

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Member::HasFields

add_default_resolve_module, add_field, extended, field, field_class, fields, global_id_field, included, inherited, own_fields

Methods included from Member::TypeSystemHelpers

#kind, #list?, #non_null?, #to_list_type, #to_non_null_type

Methods included from Member::BaseDSLMethods

#description, #graphql_name, #introspection, #mutation, #name, #overridden_graphql_name, #to_graphql, #unwrap

Methods included from Relay::TypeExtensions

#connection_type, #define_connection, #define_edge, #edge_type

Methods included from Member::CachedGraphQLDefinition

#graphql_definition, #initialize_copy

Constructor Details

#initialize(object, context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Object



15
16
17
18
# File 'lib/graphql/schema/object.rb', line 15

def initialize(object, context)
  @object = object
  @context = context
end

Instance Attribute Details

#contextGraphQL::Query::Context (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the context instance for this query

Returns:



13
14
15
# File 'lib/graphql/schema/object.rb', line 13

def context
  @context
end

#objectObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the application object this type is wrapping

Returns:

  • (Object)

    the application object this type is wrapping



10
11
12
# File 'lib/graphql/schema/object.rb', line 10

def object
  @object
end

Class Method Details

.fieldsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Include legacy-style interfaces, too



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/graphql/schema/object.rb', line 42

def fields
  all_fields = super
  interfaces.each do |int|
    if int.is_a?(GraphQL::InterfaceType)
      int_f = {}
      int.fields.each do |name, legacy_field|
        int_f[name] = field_class.from_options(name, field: legacy_field)
      end
      all_fields = int_f.merge(all_fields)
    end
  end
  all_fields
end

.implements(*new_interfaces) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/graphql/schema/object.rb', line 21

def implements(*new_interfaces)
  new_interfaces.each do |int|
    if int.is_a?(Module)
      # Include the methods here,
      # `.fields` will use the inheritance chain
      # to find inherited fields
      include(int)
    end
  end
  own_interfaces.concat(new_interfaces)
end

.interfacesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



33
34
35
# File 'lib/graphql/schema/object.rb', line 33

def interfaces
  own_interfaces + (superclass <= GraphQL::Schema::Object ? superclass.interfaces : [])
end

.kindObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



75
76
77
# File 'lib/graphql/schema/object.rb', line 75

def kind
  GraphQL::TypeKinds::OBJECT
end

.own_interfacesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
# File 'lib/graphql/schema/object.rb', line 37

def own_interfaces
  @own_interfaces ||= []
end

.to_graphqlGraphQL::ObjectType

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/graphql/schema/object.rb', line 57

def to_graphql
  obj_type = GraphQL::ObjectType.new
  obj_type.name = graphql_name
  obj_type.description = description
  obj_type.interfaces = interfaces
  obj_type.introspection = introspection
  obj_type.mutation = mutation

  fields.each do |field_name, field_inst|
    field_defn = field_inst.to_graphql
    obj_type.fields[field_defn.name] = field_defn
  end

  obj_type.[:type_class] = self

  obj_type
end