Skip to content

Commit 1261e97

Browse files
committed
Cover inline typed fragments in tests
1 parent babb089 commit 1261e97

File tree

1 file changed

+225
-0
lines changed

1 file changed

+225
-0
lines changed

juniper/src/executor_tests/executor.rs

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,36 @@ mod propagates_errors_to_nullable_fields {
839839
}
840840
}
841841

842+
#[tokio::test]
843+
async fn nullable_first_level_in_inline_typed_fragment() {
844+
// language=GraphQL
845+
let doc = r"{ inner { ...on Inner { nullableErrorField } } }";
846+
847+
for (result, errs) in [
848+
crate::execute(doc, None, &schema(), &graphql_vars! {}, &())
849+
.await
850+
.expect("async execution failed"),
851+
crate::execute_sync(doc, None, &schema(), &graphql_vars! {}, &())
852+
.expect("sync execution failed"),
853+
] {
854+
println!("Result: {result:#?}");
855+
856+
assert_eq!(
857+
result,
858+
graphql_value!({"inner": {"nullableErrorField": null}}),
859+
);
860+
861+
assert_eq!(
862+
errs,
863+
vec![ExecutionError::new(
864+
SourcePosition::new(24, 0, 24),
865+
&["inner", "nullableErrorField"],
866+
FieldError::new("Error for nullableErrorField", graphql_value!(null)),
867+
)],
868+
);
869+
}
870+
}
871+
842872
#[tokio::test]
843873
async fn non_nullable_first_level() {
844874
// language=GraphQL
@@ -923,6 +953,33 @@ mod propagates_errors_to_nullable_fields {
923953
}
924954
}
925955

956+
#[tokio::test]
957+
async fn non_nullable_first_level_in_inline_typed_fragment() {
958+
// language=GraphQL
959+
let doc = r"{ inner { ...on Inner { nonNullableErrorField } } }";
960+
961+
for (result, errs) in [
962+
crate::execute(doc, None, &schema(), &graphql_vars! {}, &())
963+
.await
964+
.expect("async execution failed"),
965+
crate::execute_sync(doc, None, &schema(), &graphql_vars! {}, &())
966+
.expect("sync execution failed"),
967+
] {
968+
println!("Result: {result:#?}");
969+
970+
assert_eq!(result, graphql_value!(null));
971+
972+
assert_eq!(
973+
errs,
974+
vec![ExecutionError::new(
975+
SourcePosition::new(24, 0, 24),
976+
&["inner", "nonNullableErrorField"],
977+
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
978+
)],
979+
);
980+
}
981+
}
982+
926983
#[tokio::test]
927984
async fn custom_error_first_level() {
928985
// language=GraphQL
@@ -1034,6 +1091,33 @@ mod propagates_errors_to_nullable_fields {
10341091
}
10351092
}
10361093

1094+
#[tokio::test]
1095+
async fn nullable_nested_level_in_inline_typed_fragment() {
1096+
// language=GraphQL
1097+
let doc = r"{ inner { nullableField { ...on Inner { nonNullableErrorField } } } }";
1098+
1099+
for (result, errs) in [
1100+
crate::execute(doc, None, &schema(), &graphql_vars! {}, &())
1101+
.await
1102+
.expect("async execution failed"),
1103+
crate::execute_sync(doc, None, &schema(), &graphql_vars! {}, &())
1104+
.expect("sync execution failed"),
1105+
] {
1106+
println!("Result: {result:#?}");
1107+
1108+
assert_eq!(result, graphql_value!({"inner": {"nullableField": null}}),);
1109+
1110+
assert_eq!(
1111+
errs,
1112+
vec![ExecutionError::new(
1113+
SourcePosition::new(40, 0, 40),
1114+
&["inner", "nullableField", "nonNullableErrorField"],
1115+
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
1116+
)],
1117+
);
1118+
}
1119+
}
1120+
10371121
#[tokio::test]
10381122
async fn nullable_in_fragment_nested_level() {
10391123
// language=GraphQL
@@ -1091,6 +1175,33 @@ mod propagates_errors_to_nullable_fields {
10911175
}
10921176
}
10931177

1178+
#[tokio::test]
1179+
async fn nullable_in_inline_typed_fragment_nested_level() {
1180+
// language=GraphQL
1181+
let doc = r"{ inner { ...on Inner { nullableField { nonNullableErrorField } } } }";
1182+
1183+
for (result, errs) in [
1184+
crate::execute(doc, None, &schema(), &graphql_vars! {}, &())
1185+
.await
1186+
.expect("async execution failed"),
1187+
crate::execute_sync(doc, None, &schema(), &graphql_vars! {}, &())
1188+
.expect("sync execution failed"),
1189+
] {
1190+
println!("Result: {result:#?}");
1191+
1192+
assert_eq!(result, graphql_value!({"inner": {"nullableField": null}}),);
1193+
1194+
assert_eq!(
1195+
errs,
1196+
vec![ExecutionError::new(
1197+
SourcePosition::new(40, 0, 40),
1198+
&["inner", "nullableField", "nonNullableErrorField"],
1199+
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
1200+
)],
1201+
);
1202+
}
1203+
}
1204+
10941205
#[tokio::test]
10951206
async fn non_nullable_nested_level() {
10961207
// language=GraphQL
@@ -1175,6 +1286,33 @@ mod propagates_errors_to_nullable_fields {
11751286
}
11761287
}
11771288

1289+
#[tokio::test]
1290+
async fn non_nullable_nested_level_in_inline_typed_fragment() {
1291+
// language=GraphQL
1292+
let doc = r"{ inner { nonNullableField { ...on Inner { nonNullableErrorField } } } }";
1293+
1294+
for (result, errs) in [
1295+
crate::execute(doc, None, &schema(), &graphql_vars! {}, &())
1296+
.await
1297+
.expect("async execution failed"),
1298+
crate::execute_sync(doc, None, &schema(), &graphql_vars! {}, &())
1299+
.expect("sync execution failed"),
1300+
] {
1301+
println!("Result: {result:#?}");
1302+
1303+
assert_eq!(result, graphql_value!(null));
1304+
1305+
assert_eq!(
1306+
errs,
1307+
vec![ExecutionError::new(
1308+
SourcePosition::new(43, 0, 43),
1309+
&["inner", "nonNullableField", "nonNullableErrorField"],
1310+
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
1311+
)],
1312+
);
1313+
}
1314+
}
1315+
11781316
#[tokio::test]
11791317
async fn non_nullable_in_fragment_nested_level() {
11801318
// language=GraphQL
@@ -1232,6 +1370,33 @@ mod propagates_errors_to_nullable_fields {
12321370
}
12331371
}
12341372

1373+
#[tokio::test]
1374+
async fn non_nullable_in_inline_typed_fragment_nested_level() {
1375+
// language=GraphQL
1376+
let doc = r"{ inner { ...on Inner { nonNullableField { nonNullableErrorField } } } }";
1377+
1378+
for (result, errs) in [
1379+
crate::execute(doc, None, &schema(), &graphql_vars! {}, &())
1380+
.await
1381+
.expect("async execution failed"),
1382+
crate::execute_sync(doc, None, &schema(), &graphql_vars! {}, &())
1383+
.expect("sync execution failed"),
1384+
] {
1385+
println!("Result: {result:#?}");
1386+
1387+
assert_eq!(result, graphql_value!(null));
1388+
1389+
assert_eq!(
1390+
errs,
1391+
vec![ExecutionError::new(
1392+
SourcePosition::new(43, 0, 43),
1393+
&["inner", "nonNullableField", "nonNullableErrorField"],
1394+
FieldError::new("Error for nonNullableErrorField", graphql_value!(null)),
1395+
)],
1396+
);
1397+
}
1398+
}
1399+
12351400
#[tokio::test]
12361401
async fn nullable_innermost() {
12371402
// language=GraphQL
@@ -1325,6 +1490,36 @@ mod propagates_errors_to_nullable_fields {
13251490
}
13261491
}
13271492

1493+
#[tokio::test]
1494+
async fn nullable_innermost_in_inline_typed_fragment() {
1495+
// language=GraphQL
1496+
let doc = r"{ inner { ...on Inner { nonNullableField { nullableErrorField } } } }";
1497+
1498+
for (result, errs) in [
1499+
crate::execute(doc, None, &schema(), &graphql_vars! {}, &())
1500+
.await
1501+
.expect("async execution failed"),
1502+
crate::execute_sync(doc, None, &schema(), &graphql_vars! {}, &())
1503+
.expect("sync execution failed"),
1504+
] {
1505+
println!("Result: {result:#?}");
1506+
1507+
assert_eq!(
1508+
result,
1509+
graphql_value!({"inner": {"nonNullableField": {"nullableErrorField": null}}}),
1510+
);
1511+
1512+
assert_eq!(
1513+
errs,
1514+
vec![ExecutionError::new(
1515+
SourcePosition::new(43, 0, 43),
1516+
&["inner", "nonNullableField", "nullableErrorField"],
1517+
FieldError::new("Error for nullableErrorField", graphql_value!(null)),
1518+
)],
1519+
);
1520+
}
1521+
}
1522+
13281523
#[tokio::test]
13291524
async fn nullable_in_fragment_innermost() {
13301525
// language=GraphQL
@@ -1388,6 +1583,36 @@ mod propagates_errors_to_nullable_fields {
13881583
}
13891584
}
13901585

1586+
#[tokio::test]
1587+
async fn nullable_in_inline_typed_fragment_innermost() {
1588+
// language=GraphQL
1589+
let doc = r"{ inner { nonNullableField { ...on Inner { nullableErrorField } } } }";
1590+
1591+
for (result, errs) in [
1592+
crate::execute(doc, None, &schema(), &graphql_vars! {}, &())
1593+
.await
1594+
.expect("async execution failed"),
1595+
crate::execute_sync(doc, None, &schema(), &graphql_vars! {}, &())
1596+
.expect("sync execution failed"),
1597+
] {
1598+
println!("Result: {result:#?}");
1599+
1600+
assert_eq!(
1601+
result,
1602+
graphql_value!({"inner": {"nonNullableField": {"nullableErrorField": null}}}),
1603+
);
1604+
1605+
assert_eq!(
1606+
errs,
1607+
vec![ExecutionError::new(
1608+
SourcePosition::new(43, 0, 43),
1609+
&["inner", "nonNullableField", "nullableErrorField"],
1610+
FieldError::new("Error for nullableErrorField", graphql_value!(null)),
1611+
)],
1612+
);
1613+
}
1614+
}
1615+
13911616
#[tokio::test]
13921617
async fn non_null_list() {
13931618
// language=GraphQL

0 commit comments

Comments
 (0)