Class: Rails::GraphQL::Type::Object::TypeObject

Inherits:
Rails::GraphQL::Type::Object show all
Defined in:
lib/rails/graphql/type/object/type_object.rb

Overview

The introspection object for any kind of type

Constant Summary collapse

FAKE_TYPES =

List and not null are not actually types, but they still need to some how exist for introspection purposes

{
  list: {
    kind: :list,
    kind_enum: 'LIST',
    name: 'List',
    gql_name: nil,
    object?: true,
    description: nil,
    of_type: nil,
  },
  non_null: {
    kind: :non_null,
    kind_enum: 'NON_NULL',
    name: 'Non-Null',
    gql_name: nil,
    object?: true,
    description: nil,
    of_type: nil,
  },
}.freeze

Constants inherited from Rails::GraphQL::Type

KINDS

Instance Attribute Summary

Attributes included from Helpers::Instantiable

#event

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rails::GraphQL::Type::Object

=~, implements, implements?, inspect

Methods included from Helpers::WithAssignment

#assigned?, #assigned_class, #assigned_to, #assigned_to=, extended, #register!, #safe_assigned_class, #valid_assignment?

Methods included from Helpers::WithFields

#change_field, #configure_field, #disable_fields, #enable_fields, #enabled_fields, extended, #field, #field_names, #find_by_gid, #find_field, #find_field!, #has_field?, #import, #import_all, #proxy_field, #safe_field, #validate!

Methods inherited from Rails::GraphQL::Type

=~, base_type, create!, decorate, find_by_gid, gid_base_class, input_type?, kind, kind_enum, leaf_type?, operational?, output_type?, to_gql_backtrace

Methods included from Helpers::WithDirectives

#all_directive_events, #all_directive_listeners, #directive_events?, #directive_listeners?, extended, included, #initialize_copy, #use, #using?, #validate!

Methods included from Helpers::WithGlobalID

#to_gid_param, #to_global_id

Methods included from Helpers::Registerable

#aliases, extended, #inherited, #register!, #registered?

Class Method Details

.fake_type_object(type, subtype) ⇒ Object



38
39
40
# File 'lib/rails/graphql/type/object/type_object.rb', line 38

def self.fake_type_object(type, subtype)
  FAKE_TYPES[type].merge(of_type: subtype)
end

.valid_member?(value) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/rails/graphql/type/object/type_object.rb', line 34

def self.valid_member?(value)
  value.is_a?(OpenStruct) ? value.try(:object?) : super
end

Instance Method Details

#enum_values(include_deprecated:) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/rails/graphql/type/object/type_object.rb', line 125

def enum_values(include_deprecated:)
  return if fake_type? || !current.enum?

  descriptions = all_value_description
  deprecated = all_deprecated_values

  list = all_values.lazy
  list = list.reject { |value| deprecated.key?(value) } \
    unless include_deprecated || deprecated.nil?

  list.map do |value|
    {
      name: value,
      description: descriptions.try(:[], value),
      is_deprecated: (deprecated.nil? ? false : deprecated.key?(value)),
      deprecation_reason: deprecated.try(:[], value),
    }
  end
end

#fields(include_deprecated:) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/rails/graphql/type/object/type_object.rb', line 106

def fields(include_deprecated:)
  return if fake_type? || !(current.object? || current.interface?)

  list =
    if current.respond_to?(:enabled_fields)
      current.enabled_fields
    else
      current.fields.values.select(&:enabled?)
    end

  unless include_deprecated
    list = list.reject { |field| field.using?(deprecated_directive) }
  end

  list.reject(&:internal?).sort_by do |field|
    (field.name == :id) ? '' : field.gql_name
  end
end

#input_fieldsObject



160
161
162
163
# File 'lib/rails/graphql/type/object/type_object.rb', line 160

def input_fields
  return if fake_type? || !current.input?
  current.enabled_fields || EMPTY_ARRAY
end

#interfacesObject



145
146
147
148
# File 'lib/rails/graphql/type/object/type_object.rb', line 145

def interfaces
  return if fake_type? || !current.object?
  current.all_interfaces || EMPTY_ARRAY
end

#possible_typesObject



150
151
152
153
154
155
156
157
158
# File 'lib/rails/graphql/type/object/type_object.rb', line 150

def possible_types
  return if fake_type?

  if current.interface?
    current.all_types || EMPTY_ARRAY
  elsif current.union?
    current.all_members || EMPTY_ARRAY
  end
end

#specified_by_urlObject



98
99
100
101
102
103
104
# File 'lib/rails/graphql/type/object/type_object.rb', line 98

def specified_by_url
  return if fake_type? || !current.scalar?

  current.all_directives&.find do |dir|
    dir.is_a?(Directive::SpecifiedByDirective)
  end&.args&.url
end