Skip to content

Commit c4b5910

Browse files
committed
Use types instead of names for tracking possible_types
1 parent b4402c9 commit c4b5910

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

lib/graphql/schema.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def possible_types(type = nil, context = GraphQL::Query::NullContext.instance)
506506
if type.kind.union?
507507
type.possible_types(context: context)
508508
else
509-
stored_possible_types = own_possible_types[type.graphql_name]
509+
stored_possible_types = own_possible_types[type]
510510
visible_possible_types = if stored_possible_types && type.kind.interface?
511511
stored_possible_types.select do |possible_type|
512512
possible_type.interfaces(context).include?(type)
@@ -515,7 +515,7 @@ def possible_types(type = nil, context = GraphQL::Query::NullContext.instance)
515515
stored_possible_types
516516
end
517517
visible_possible_types ||
518-
introspection_system.possible_types[type.graphql_name] ||
518+
introspection_system.possible_types[type] ||
519519
(
520520
superclass.respond_to?(:possible_types) ?
521521
superclass.possible_types(type, context) :
@@ -1497,7 +1497,7 @@ def own_orphan_types
14971497
end
14981498

14991499
def own_possible_types
1500-
@own_possible_types ||= {}
1500+
@own_possible_types ||= {}.tap(&:compare_by_identity)
15011501
end
15021502

15031503
def own_union_memberships

lib/graphql/schema/addition.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def update_type_owner(owner, type)
9595
# It's a union with possible_types
9696
# Replace the item by class name
9797
owner.assign_type_membership_object_type(type)
98-
@possible_types[owner.graphql_name] = owner.possible_types
98+
@possible_types[owner] = owner.possible_types
9999
elsif type.kind.interface? && (owner.kind.object? || owner.kind.interface?)
100100
new_interfaces = []
101101
owner.interfaces.each do |int_t|
@@ -110,7 +110,7 @@ def update_type_owner(owner, type)
110110
end
111111
owner.implements(*new_interfaces)
112112
new_interfaces.each do |int|
113-
pt = @possible_types[int.graphql_name] ||= []
113+
pt = @possible_types[int] ||= []
114114
if !pt.include?(owner) && owner.is_a?(Class)
115115
pt << owner
116116
end
@@ -229,7 +229,7 @@ def add_type(type, owner:, late_types:, path:)
229229
end
230230
end
231231
if type.kind.union?
232-
@possible_types[type.graphql_name] = type.all_possible_types
232+
@possible_types[type] = type.all_possible_types
233233
path.push("possible_types")
234234
type.all_possible_types.each do |t|
235235
add_type(t, owner: type, late_types: late_types, path: path)
@@ -244,7 +244,7 @@ def add_type(type, owner:, late_types:, path:)
244244
path.pop
245245
end
246246
if type.kind.object?
247-
possible_types_for_this_name = @possible_types[type.graphql_name] ||= []
247+
possible_types_for_this_name = @possible_types[type] ||= []
248248
possible_types_for_this_name << type
249249
end
250250

@@ -256,7 +256,7 @@ def add_type(type, owner:, late_types:, path:)
256256
interface_type = interface_type_membership.abstract_type
257257
# We can get these now; we'll have to get late-bound types later
258258
if interface_type.is_a?(Module) && type.is_a?(Class)
259-
implementers = @possible_types[interface_type.graphql_name] ||= []
259+
implementers = @possible_types[interface_type] ||= []
260260
implementers << type
261261
end
262262
when String, Schema::LateBoundType

lib/graphql/schema/introspection_system.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def initialize(schema)
2525
load_constant(:DirectiveLocationEnum)
2626
]
2727
@types = {}
28-
@possible_types = {}
28+
@possible_types = {}.tap(&:compare_by_identity)
2929
type_defns.each do |t|
3030
@types[t.graphql_name] = t
31-
@possible_types[t.graphql_name] = [t]
31+
@possible_types[t] = [t]
3232
end
3333
@entry_point_fields =
3434
if schema.disable_introspection_entry_points?

0 commit comments

Comments
 (0)