Skip to content

Commit 0e6c0a3

Browse files
committed
Add missing tests
1 parent 510dbd3 commit 0e6c0a3

File tree

1 file changed

+177
-8
lines changed

1 file changed

+177
-8
lines changed

tests/execution/test_stream.py

Lines changed: 177 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ async def get_friend(i):
10931093
return {"nonNullName": throw() if i < 0 else friends[i].name}
10941094

10951095
def get_friends(_info):
1096-
return [get_friend(0), get_friend(-1), get_friend(1)]
1096+
return [get_friend(i) for i in (0, -1, 1)]
10971097

10981098
result = await complete(
10991099
document,
@@ -1136,7 +1136,68 @@ def get_friends(_info):
11361136
]
11371137

11381138
@pytest.mark.asyncio()
1139-
async def handles_async_error_in_complete_value_for_non_nullable_list():
1139+
async def handles_nested_async_error_in_complete_value_after_initial_count():
1140+
document = parse(
1141+
"""
1142+
query {
1143+
friendList @stream(initialCount: 1) {
1144+
nonNullName
1145+
}
1146+
}
1147+
"""
1148+
)
1149+
1150+
async def get_friend_name(i):
1151+
await sleep(0)
1152+
if i < 0:
1153+
raise RuntimeError("Oops")
1154+
return friends[i].name
1155+
1156+
def get_friends(_info):
1157+
return [{"nonNullName": get_friend_name(i)} for i in (0, -1, 1)]
1158+
1159+
result = await complete(
1160+
document,
1161+
{
1162+
"friendList": get_friends,
1163+
},
1164+
)
1165+
assert result == [
1166+
{
1167+
"data": {
1168+
"friendList": [{"nonNullName": "Luke"}],
1169+
},
1170+
"hasNext": True,
1171+
},
1172+
{
1173+
"incremental": [
1174+
{
1175+
"items": [None],
1176+
"path": ["friendList", 1],
1177+
"errors": [
1178+
{
1179+
"message": "Oops",
1180+
"locations": [{"line": 4, "column": 17}],
1181+
"path": ["friendList", 1, "nonNullName"],
1182+
},
1183+
],
1184+
},
1185+
],
1186+
"hasNext": True,
1187+
},
1188+
{
1189+
"incremental": [
1190+
{
1191+
"items": [{"nonNullName": "Han"}],
1192+
"path": ["friendList", 2],
1193+
}
1194+
],
1195+
"hasNext": False,
1196+
},
1197+
]
1198+
1199+
@pytest.mark.asyncio()
1200+
async def handles_async_error_in_complete_value_after_initial_count_non_null():
11401201
document = parse(
11411202
"""
11421203
query {
@@ -1155,7 +1216,7 @@ async def get_friend(i):
11551216
return {"nonNullName": throw() if i < 0 else friends[i].name}
11561217

11571218
def get_friends(_info):
1158-
return [get_friend(0), get_friend(-1), get_friend(1)]
1219+
return [get_friend(i) for i in (0, -1, 1)]
11591220

11601221
result = await complete(
11611222
document,
@@ -1173,7 +1234,7 @@ def get_friends(_info):
11731234
{
11741235
"incremental": [
11751236
{
1176-
"items": None,
1237+
"items": [None],
11771238
"path": ["nonNullFriendList", 1],
11781239
"errors": [
11791240
{
@@ -1189,7 +1250,59 @@ def get_friends(_info):
11891250
]
11901251

11911252
@pytest.mark.asyncio()
1192-
async def handles_async_error_after_initial_count_reached_from_async_iterable():
1253+
async def handles_nested_async_error_in_complete_value_after_initial_non_null():
1254+
document = parse(
1255+
"""
1256+
query {
1257+
nonNullFriendList @stream(initialCount: 1) {
1258+
nonNullName
1259+
}
1260+
}
1261+
"""
1262+
)
1263+
1264+
async def get_friend_name(i):
1265+
await sleep(0)
1266+
if i < 0:
1267+
raise RuntimeError("Oops")
1268+
return friends[i].name
1269+
1270+
def get_friends(_info):
1271+
return [{"nonNullName": get_friend_name(i)} for i in (0, -1, 1)]
1272+
1273+
result = await complete(
1274+
document,
1275+
{
1276+
"nonNullFriendList": get_friends,
1277+
},
1278+
)
1279+
assert result == [
1280+
{
1281+
"data": {
1282+
"nonNullFriendList": [{"nonNullName": "Luke"}],
1283+
},
1284+
"hasNext": True,
1285+
},
1286+
{
1287+
"incremental": [
1288+
{
1289+
"items": None,
1290+
"path": ["nonNullFriendList", 1],
1291+
"errors": [
1292+
{
1293+
"message": "Oops",
1294+
"locations": [{"line": 4, "column": 17}],
1295+
"path": ["friendList", 1, "nonNullName"],
1296+
},
1297+
],
1298+
},
1299+
],
1300+
"hasNext": False,
1301+
},
1302+
]
1303+
1304+
@pytest.mark.asyncio()
1305+
async def handles_async_error_in_complete_value_after_initial_from_async_iterable():
11931306
document = parse(
11941307
"""
11951308
query {
@@ -1208,9 +1321,8 @@ async def get_friend(i):
12081321
return {"nonNullName": throw() if i < 0 else friends[i].name}
12091322

12101323
async def get_friends(_info):
1211-
yield await get_friend(0)
1212-
yield await get_friend(-1)
1213-
yield await get_friend(1)
1324+
for i in 0, -1, 1:
1325+
yield await get_friend(i)
12141326

12151327
result = await complete(
12161328
document,
@@ -1248,6 +1360,63 @@ async def get_friends(_info):
12481360
"path": ["friendList", 2],
12491361
},
12501362
],
1363+
"hasNext": True,
1364+
},
1365+
{
1366+
"hasNext": False,
1367+
},
1368+
]
1369+
1370+
@pytest.mark.asyncio()
1371+
async def handles_async_error_in_complete_value_from_async_iterable_non_null():
1372+
document = parse(
1373+
"""
1374+
query {
1375+
nonNullFriendList @stream(initialCount: 1) {
1376+
nonNullName
1377+
}
1378+
}
1379+
"""
1380+
)
1381+
1382+
async def throw():
1383+
raise RuntimeError("Oops")
1384+
1385+
async def get_friend(i):
1386+
await sleep(0)
1387+
return {"nonNullName": throw() if i < 0 else friends[i].name}
1388+
1389+
async def get_friends(_info):
1390+
for i in 0, -1, 1:
1391+
yield await get_friend(i)
1392+
1393+
result = await complete(
1394+
document,
1395+
{
1396+
"nonNullFriendList": get_friends,
1397+
},
1398+
)
1399+
assert result == [
1400+
{
1401+
"data": {
1402+
"nonNullFriendList": [{"nonNullName": "Luke"}],
1403+
},
1404+
"hasNext": True,
1405+
},
1406+
{
1407+
"incremental": [
1408+
{
1409+
"items": [None],
1410+
"path": ["nonNullFriendList", 1],
1411+
"errors": [
1412+
{
1413+
"message": "Oops",
1414+
"locations": [{"line": 4, "column": 17}],
1415+
"path": ["friendList", 1, "nonNullName"],
1416+
},
1417+
],
1418+
},
1419+
],
12511420
"hasNext": False,
12521421
},
12531422
]

0 commit comments

Comments
 (0)