Skip to content

Commit 726cac5

Browse files
committed
Fix a bug in the list_value visitor and add a test for it
1 parent 1e7de3f commit 726cac5

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

GraphQLService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void ValueVisitor::visitListValue(const peg::ast_node& listValue)
177177

178178
for (const auto& child : listValue.children)
179179
{
180-
visitor.visit(*child->children.back());
180+
visitor.visit(*child);
181181
_value.emplace_back(visitor.getValue());
182182
}
183183
}

tests.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,54 @@ TEST_F(TodayServiceCase, NestedFragmentDirectives)
785785
}
786786
}
787787

788+
TEST_F(TodayServiceCase, QueryAppointmentsById)
789+
{
790+
auto ast = R"(query SpecificAppointment($appointmentId: ID!) {
791+
appointmentsById(ids: [$appointmentId]) {
792+
appointmentId: id
793+
subject
794+
when
795+
isNow
796+
}
797+
})"_graphql;
798+
response::Value variables(response::Type::Map);
799+
variables.emplace_back("appointmentId", response::Value(std::string("ZmFrZUFwcG9pbnRtZW50SWQ=")));
800+
auto state = std::make_shared<today::RequestState>(12);
801+
auto result = _service->resolve(state, *ast->root, "", std::move(variables)).get();
802+
EXPECT_EQ(size_t(1), _getAppointmentsCount) << "today service lazy loads the appointments and caches the result";
803+
EXPECT_GE(size_t(1), _getTasksCount) << "today service lazy loads the tasks and caches the result";
804+
EXPECT_GE(size_t(1), _getUnreadCountsCount) << "today service lazy loads the unreadCounts and caches the result";
805+
EXPECT_EQ(size_t(12), state->appointmentsRequestId) << "today service passed the same RequestState";
806+
EXPECT_EQ(size_t(0), state->tasksRequestId) << "today service did not call the loader";
807+
EXPECT_EQ(size_t(0), state->unreadCountsRequestId) << "today service did not call the loader";
808+
EXPECT_EQ(size_t(1), state->loadAppointmentsCount) << "today service called the loader once";
809+
EXPECT_EQ(size_t(0), state->loadTasksCount) << "today service did not call the loader";
810+
EXPECT_EQ(size_t(0), state->loadUnreadCountsCount) << "today service did not call the loader";
811+
812+
try
813+
{
814+
ASSERT_TRUE(result.type() == response::Type::Map);
815+
auto errorsItr = result.find("errors");
816+
if (errorsItr != result.get<const response::MapType&>().cend())
817+
{
818+
FAIL() << response::toJSON(response::Value(errorsItr->second));
819+
}
820+
const auto data = service::ScalarArgument::require("data", result);
821+
822+
const auto appointmentsById = service::ScalarArgument::require<service::TypeModifier::List>("appointmentsById", data);
823+
ASSERT_EQ(size_t(1), appointmentsById.size());
824+
const auto& appointmentEntry = appointmentsById.front();
825+
EXPECT_EQ(_fakeAppointmentId, service::IdArgument::require("appointmentId", appointmentEntry)) << "id should match in base64 encoding";
826+
EXPECT_EQ("Lunch?", service::StringArgument::require("subject", appointmentEntry)) << "subject should match";
827+
EXPECT_EQ("tomorrow", service::StringArgument::require("when", appointmentEntry)) << "when should match";
828+
EXPECT_FALSE(service::BooleanArgument::require("isNow", appointmentEntry)) << "isNow should match";
829+
}
830+
catch (const service::schema_exception& ex)
831+
{
832+
FAIL() << response::toJSON(response::Value(ex.getErrors()));
833+
}
834+
}
835+
788836
TEST(ArgumentsCase, ListArgumentStrings)
789837
{
790838
auto parsed = response::parseJSON(R"js({"value":[

0 commit comments

Comments
 (0)