@@ -1343,3 +1343,73 @@ TEST_F(TodayServiceCase, BlockingAsyncExpensive)
13431343 FAIL () << response::toJSON (ex.getErrors ());
13441344 }
13451345}
1346+
1347+ TEST_F (TodayServiceCase, QueryAppointmentsThroughUnionTypeFragment)
1348+ {
1349+ auto query = R"( {
1350+ appointments {
1351+ edges {
1352+ node {
1353+ ...AppointmentUnionFragment
1354+ }
1355+ }
1356+ }
1357+ }
1358+
1359+ fragment AppointmentUnionFragment on UnionType {
1360+ ...on Appointment {
1361+ appointmentId: id
1362+ subject
1363+ when
1364+ isNow
1365+ }
1366+ })" _graphql;
1367+ response::Value variables (response::Type::Map);
1368+ auto state = std::make_shared<today::RequestState>(20 );
1369+ auto result = _service->resolve (state, query, " " , std::move (variables)).get ();
1370+ EXPECT_EQ (size_t (1 ), _getAppointmentsCount)
1371+ << " today service lazy loads the appointments and caches the result" ;
1372+ EXPECT_GE (size_t (1 ), _getTasksCount)
1373+ << " today service lazy loads the tasks and caches the result" ;
1374+ EXPECT_GE (size_t (1 ), _getUnreadCountsCount)
1375+ << " today service lazy loads the unreadCounts and caches the result" ;
1376+ EXPECT_EQ (size_t (20 ), state->appointmentsRequestId )
1377+ << " today service passed the same RequestState" ;
1378+ EXPECT_EQ (size_t (0 ), state->tasksRequestId ) << " today service did not call the loader" ;
1379+ EXPECT_EQ (size_t (0 ), state->unreadCountsRequestId ) << " today service did not call the loader" ;
1380+ EXPECT_EQ (size_t (1 ), state->loadAppointmentsCount ) << " today service called the loader once" ;
1381+ EXPECT_EQ (size_t (0 ), state->loadTasksCount ) << " today service did not call the loader" ;
1382+ EXPECT_EQ (size_t (0 ), state->loadUnreadCountsCount ) << " today service did not call the loader" ;
1383+
1384+ try
1385+ {
1386+ ASSERT_TRUE (result.type () == response::Type::Map);
1387+ auto errorsItr = result.find (" errors" );
1388+ if (errorsItr != result.get <response::MapType>().cend ())
1389+ {
1390+ FAIL () << response::toJSON (response::Value (errorsItr->second ));
1391+ }
1392+ const auto data = service::ScalarArgument::require (" data" , result);
1393+
1394+ const auto appointments = service::ScalarArgument::require (" appointments" , data);
1395+ const auto appointmentEdges =
1396+ service::ScalarArgument::require<service::TypeModifier::List>(" edges" , appointments);
1397+ ASSERT_EQ (1 , appointmentEdges.size ()) << " appointments should have 1 entry" ;
1398+ ASSERT_TRUE (appointmentEdges[0 ].type () == response::Type::Map)
1399+ << " appointment should be an object" ;
1400+ const auto appointmentNode = service::ScalarArgument::require (" node" , appointmentEdges[0 ]);
1401+ EXPECT_EQ (_fakeAppointmentId,
1402+ service::IdArgument::require (" appointmentId" , appointmentNode))
1403+ << " id should match in base64 encoding" ;
1404+ EXPECT_EQ (" Lunch?" , service::StringArgument::require (" subject" , appointmentNode))
1405+ << " subject should match" ;
1406+ EXPECT_EQ (" tomorrow" , service::StringArgument::require (" when" , appointmentNode))
1407+ << " when should match" ;
1408+ EXPECT_FALSE (service::BooleanArgument::require (" isNow" , appointmentNode))
1409+ << " isNow should match" ;
1410+ }
1411+ catch (service::schema_exception& ex)
1412+ {
1413+ FAIL () << response::toJSON (ex.getErrors ());
1414+ }
1415+ }
0 commit comments