Class: GraphQL::Schema::IntrospectionSystem

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ IntrospectionSystem

Returns a new instance of IntrospectionSystem.



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
44
45
46
47
# File 'lib/graphql/schema/introspection_system.rb', line 9

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 = {}.compare_by_identity
  type_defns.each do |t|
    @types[t.graphql_name] = t
    @possible_types[t] = [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
  @entry_point_fields.each { |k, v| v.dynamic_introspection = true }
  @dynamic_fields = get_fields_from_class(class_sym: :DynamicFields)
  @dynamic_fields.each { |k, v| v.dynamic_introspection = true }
end

Instance Attribute Details

#possible_types ⇒ Object (readonly)

Returns the value of attribute possible_types.



7
8
9
# File 'lib/graphql/schema/introspection_system.rb', line 7

def possible_types
  @possible_types
end

#types ⇒ Object (readonly)

Returns the value of attribute types.



7
8
9
# File 'lib/graphql/schema/introspection_system.rb', line 7

def types
  @types
end

Instance Method Details

#dynamic_field(name:) ⇒ Object



61
62
63
# File 'lib/graphql/schema/introspection_system.rb', line 61

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

#dynamic_fields ⇒ Object



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

def dynamic_fields
  @dynamic_fields.values
end

#entry_point(name:) ⇒ Object



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

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

#entry_points ⇒ Object



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

def entry_points
  @entry_point_fields.values
end

#resolve_late_bindings ⇒ Object

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

  • Object — void


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/graphql/schema/introspection_system.rb', line 73

def resolve_late_bindings # :nodoc:
  @types.each do |name, t|
    if t.kind.fields?
      t.all_field_definitions.each do |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