10000 polish: add additional test for filtering · graphql-python/graphql-core@e34f020 · GitHub
[go: up one dir, main page]

Skip to content

Commit e34f020

Browse files
committed
polish: add additional test for filtering
Replicates graphql/graphql-js@bd5aae7
1 parent 4a87525 commit e34f020

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/graphql/execution/execute.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,7 @@ async def complete_async_iterator_value(
11721172
) -> List[Any]:
11731173
"""Complete an async iterator.
11741174
1175-
Complete a async iterator value by completing the result and calling
1175+
Complete an async iterator value by completing the result and calling
11761176
recursively until all the results are completed.
11771177
"""
11781178
errors = async_payload_record.errors if async_payload_record else self.errors

tests/execution/test_stream.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ async def anext(iterator): # noqa: A001
4343

4444

4545
class Friend(NamedTuple):
46-
name: str
4746
id: int
47+
name: str
4848

4949

50-
friends = [Friend("Luke", 1), Friend("Han", 2), Friend("Leia", 3)]
50+
friends = [Friend(1, "Luke"), Friend(2, "Han"), Friend(3, "Leia")]
5151

5252
query = GraphQLObjectType(
5353
"Query",
@@ -1186,6 +1186,50 @@ async def friend_list(_info):
11861186
},
11871187
}
11881188

1189+
@pytest.mark.asyncio()
1190+
@pytest.mark.filterwarnings("ignore:.* was never awaited:RuntimeWarning")
1191+
async def filters_payloads_that_are_nulled_by_a_later_synchronous_error():
1192+
document = parse(
1193+
"""
1194+
query {
1195+
nestedObject {
1196+
nestedFriendList @stream(initialCount: 0) {
1197+
name
1198+
}
1199+
nonNullScalarField
1200+
}
1201+
}
1202+
"""
1203+
)
1204+
1205+
async def friend_list(_info):
1206+
await sleep(0)
1207+
yield friends[0]
1208+
1209+
result = await complete(
1210+
document,
1211+
{
1212+
"nestedObject": {
1213+
"nestedFriendList": friend_list,
1214+
"nonNullScalarField": lambda _info: None,
1215+
}
1216+
},
1217+
)
1218+
1219+
assert result == {
1220+
"errors": [
1221+
{
1222+
"message": "Cannot return null for non-nullable field"
1223+
" NestedObject.nonNullScalarField.",
1224+
"locations": [{"line": 7, "column": 17}],
1225+
"path": ["nestedObject", "nonNullScalarField"],
1226+
},
1227+
],
1228+
"data": {
1229+
"nestedObject": None,
1230+
},
1231+
}
1232+
11891233
@pytest.mark.asyncio()
11901234
async def does_not_filter_payloads_when_null_error_is_in_a_different_path():
11911235
document = parse(

0 commit comments

Comments
 (0)
0