|
1 | 1 | from collections import defaultdict
|
2 | 2 | from functools import cmp_to_key
|
3 |
| -from typing import Any, Dict, List, Set, Union, cast |
| 3 | +from typing import Any, Dict, List, Union, cast |
4 | 4 |
|
5 | 5 | from ...type import (
|
6 | 6 | GraphQLAbstractType,
|
@@ -72,22 +72,23 @@ def get_suggested_type_names(
|
72 | 72 | return []
|
73 | 73 |
|
74 | 74 | type_ = cast(GraphQLAbstractType, type_)
|
75 |
| - suggested_types: Set[Union[GraphQLObjectType, GraphQLInterfaceType]] = set() |
| 75 | + # Use a dict instead of a set for stable sorting when usage counts are the same |
| 76 | + suggested_types: Dict[Union[GraphQLObjectType, GraphQLInterfaceType], None] = {} |
76 | 77 | usage_count: Dict[str, int] = defaultdict(int)
|
77 | 78 | for possible_type in schema.get_possible_types(type_):
|
78 | 79 | if field_name not in possible_type.fields:
|
79 | 80 | continue
|
80 | 81 |
|
81 | 82 | # This object type defines this field.
|
82 |
| - suggested_types.add(possible_type) |
| 83 | + suggested_types[possible_type] = None |
83 | 84 | usage_count[possible_type.name] = 1
|
84 | 85 |
|
85 | 86 | for possible_interface in possible_type.interfaces:
|
86 | 87 | if field_name not in possible_interface.fields:
|
87 | 88 | continue
|
88 | 89 |
|
89 | 90 | # This interface type defines this field.
|
90 |
| - suggested_types.add(possible_interface) |
| 91 | + suggested_types[possible_interface] = None |
91 | 92 | usage_count[possible_interface.name] += 1
|
92 | 93 |
|
93 | 94 | def cmp(
|
|
0 commit comments