Skip to content

Commit cd2d6a8

Browse files
committed
Fix incremental_publisher logic around selecting id/sub_path
Replicates graphql/graphql-js@e081838
1 parent 1657733 commit cd2d6a8

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/graphql/execution/incremental_publisher.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,24 +1057,25 @@ def _get_incremental_defer_result(
10571057
"""Get the incremental defer result from the grouped field set record."""
10581058
data = deferred_grouped_field_set_record.data
10591059
fragment_records = deferred_grouped_field_set_record.deferred_fragment_records
1060-
max_length = len(fragment_records[0].path)
1061-
max_index = 0
1062-
for i in range(1, len(fragment_records)):
1063-
fragment_record = fragment_records[i]
1060+
max_length: int | None = None
1061+
id_with_longest_path: str | None = None
1062+
for fragment_record in fragment_records:
1063+
if fragment_record.id is None:
1064+
continue
10641065
length = len(fragment_record.path)
1065-
if length > max_length:
1066+
if max_length is None or length > max_length:
10661067
max_length = length
1067-
max_index = i
1068-
record_with_longest_path = fragment_records[max_index]
1069-
longest_path = record_with_longest_path.path
1070-
sub_path = deferred_grouped_field_set_record.path[len(longest_path) :]
1071-
id_ = record_with_longest_path.id
1068+
id_with_longest_path = fragment_record.id
1069+
1070+
sub_path = deferred_grouped_field_set_record.path[max_length:]
1071+
10721072
return IncrementalDeferResult(
10731073
# safe because `data` is always defined when the record is completed
10741074
data, # type: ignore
1075-
# safe because `id` is defined
1076-
# once the fragment has been released as pending
1077-
id_, # type: ignore
1075+
# safe because `id` is always defined once the fragment has been released
1076+
# as pending and at least one fragment has been completed, so must have been
1077+
# released as pending
1078+
id_with_longest_path, # type: ignore
10781079
sub_path or None,
10791080
)
10801081

0 commit comments

Comments
 (0)