Class: GraphQL::Schema::IntrospectionSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/schema/introspection_system.rb

Defined Under Namespace

Classes: PerFieldProxyResolve

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ IntrospectionSystem

Returns a new instance of IntrospectionSystem.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/graphql/schema/introspection_system.rb', line 7

def initialize(schema)
  @schema = schema
  @class_based = !!@schema.is_a?(Class)
  @built_in_namespace = GraphQL::Introspection
  @custom_namespace = if @class_based
    schema.introspection || @built_in_namespace
  else
    schema.introspection_namespace || @built_in_namespace
  end

  type_defns = [
    load_constant(:SchemaType),
    load_constant(:TypeType),
    load_constant(:FieldType),
    load_constant(:DirectiveType),
    load_constant(:EnumValueType),
    load_constant(:InputValueType),
    load_constant(:TypeKindEnum),
    load_constant(:DirectiveLocationEnum)
  ]
  @types = {}
  @possible_types = {}
  type_defns.each do |t|
    @types[t.graphql_name] = t
    @possible_types[t.graphql_name] = [t]
  end
  @entry_point_fields =
    if schema.disable_introspection_entry_points?
      {}
    else
      entry_point_fields = get_fields_from_class(class_sym: :EntryPoints)
      entry_point_fields.delete('__schema') if schema.disable_schema_introspection_entry_point?
      entry_point_fields.delete('__type') if schema.disable_type_introspection_entry_point?
      entry_point_fields
    end
  @dynamic_fields = get_fields_from_class(class_sym: :DynamicFields)
end

Instance Attribute Details

#possible_typesObject (readonly)

Returns the value of attribute possible_types.



5
6
7
# File 'lib/graphql/schema/introspection_system.rb', line 5

def possible_types
  @possible_types
end

#typesObject (readonly)

Returns the value of attribute types.



5
6
7
# File 'lib/graphql/schema/introspection_system.rb', line 5

def types
  @types
end

Instance Method Details

#dynamic_field(name:) ⇒ Object



57
58
59
# File 'lib/graphql/schema/introspection_system.rb', line 57

def dynamic_field(name:)
  @dynamic_fields[name]
end

#dynamic_fieldsObject



53
54
55
# File 'lib/graphql/schema/introspection_system.rb', line 53

def dynamic_fields
  @dynamic_fields.values
end

#entry_point(name:) ⇒ Object



49
50
51
# File 'lib/graphql/schema/introspection_system.rb', line 49

def entry_point(name:)
  @entry_point_fields[name]
end

#entry_pointsObject



45
46
47
# File 'lib/graphql/schema/introspection_system.rb', line 45

def entry_points
  @entry_point_fields.values
end

#resolve_late_bindingsObject

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.

The introspection system is prepared with a bunch of LateBoundTypes. Replace those with the objects that they refer to, since LateBoundTypes aren’t handled at runtime.

Returns:

  • void



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/graphql/schema/introspection_system.rb', line 67

def resolve_late_bindings
  @types.each do |name, t|
    if t.kind.fields?
      t.fields.each do |_name, field_defn|
        field_defn.type = resolve_late_binding(field_defn.type)
      end
    end
  end

  @entry_point_fields.each do |name, f|
    f.type = resolve_late_binding(f.type)
  end

  @dynamic_fields.each do |name, f|
    f.type = resolve_late_binding(f.type)
  end
  nil
end