Skip to content

Commit d549878

Browse files
committed
fields_on_correct_type: produce stable sort order
Backport from main branch
1 parent ac9c674 commit d549878

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/graphql/validation/rules/fields_on_correct_type.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections import defaultdict
22
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
44

55
from ...type import (
66
GraphQLAbstractType,
@@ -72,22 +72,23 @@ def get_suggested_type_names(
7272
return []
7373

7474
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] = {}
7677
usage_count: Dict[str, int] = defaultdict(int)
7778
for possible_type in schema.get_possible_types(type_):
7879
if field_name not in possible_type.fields:
7980
continue
8081

8182
# This object type defines this field.
82-
suggested_types.add(possible_type)
83+
suggested_types[possible_type] = None
8384
usage_count[possible_type.name] = 1
8485

8586
for possible_interface in possible_type.interfaces:
8687
if field_name not in possible_interface.fields:
8788
continue
8889

8990
# This interface type defines this field.
90-
suggested_types.add(possible_interface)
91+
suggested_types[possible_interface] = None
9192
usage_count[possible_interface.name] += 1
9293

9394
def cmp(

0 commit comments

Comments
 (0)