Skip to content

Fix boolean list input #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions include/graphqlservice/GraphQLClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,16 @@ struct ModifiedVariable
response::Value result { response::Type::List };

result.reserve(listValue.size());
std::ranges::for_each(listValue, [&result](auto& value) {
result.emplace_back(serialize<Other...>(std::move(value)));
});
if constexpr(std::is_same_v<Type,bool>){
for (auto const v: listValue)
result.emplace_back(Variable<bool>::serialize(bool{v}));
}
else{
std::ranges::for_each(listValue, [&result](auto& value) {
result.emplace_back(serialize<Other...>(std::move(value)));
});
}

listValue.clear();

return result;
Expand Down Expand Up @@ -217,11 +224,19 @@ struct ModifiedVariable
duplicate(const typename VariableTraits<Type, Modifier, Other...>::type& listValue)
requires ListModifier<Modifier>
{
typename VariableTraits<Type, Modifier, Other...>::type result(listValue.size());

std::ranges::transform(listValue, result.begin(), duplicate<Other...>);

return result;
if constexpr(std::is_same_v<Type,bool>){
typename VariableTraits<Type, Modifier, Other...>::type result;
result.reserve(listValue.size());
for (auto const v: listValue)
result.push_back(v);
return result;
}
else
{
typename VariableTraits<Type, Modifier, Other...>::type result(listValue.size());
std::ranges::transform(listValue, result.begin(), duplicate<Other...>);
return result;
}
}
};

Expand Down
18 changes: 13 additions & 5 deletions include/graphqlservice/GraphQLService.h
Original file line number Diff line number Diff line change
Expand Up @@ -795,11 +795,19 @@ struct ModifiedArgument
duplicate(const typename ArgumentTraits<Type, Modifier, Other...>::type& listValue)
requires ListModifier<Modifier>
{
typename ArgumentTraits<Type, Modifier, Other...>::type result(listValue.size());

std::ranges::transform(listValue, result.begin(), duplicate<Other...>);

return result;
if constexpr(std::is_same_v<Type,bool>){
typename ArgumentTraits<Type, Modifier, Other...>::type result;
result.reserve(listValue.size());
for (auto const v: listValue)
result.push_back(v);
return result;
}
else
{
typename ArgumentTraits<Type, Modifier, Other...>::type result(listValue.size());
std::ranges::transform(listValue, result.begin(), duplicate<Other...>);
return result;
}
}
};

Expand Down
9 changes: 8 additions & 1 deletion samples/client/multiple/MultipleQueriesClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ CompleteTaskInput::CompleteTaskInput() noexcept
, testTaskState {}
, isComplete {}
, clientMutationId {}
, boolList {}
{
// Explicit definition to prevent ODR violations when LTO is enabled.
}
Expand All @@ -139,11 +140,13 @@ CompleteTaskInput::CompleteTaskInput(
response::IdType idArg,
std::optional<TaskState> testTaskStateArg,
std::optional<bool> isCompleteArg,
std::optional<std::string> clientMutationIdArg) noexcept
std::optional<std::string> clientMutationIdArg,
std::optional<std::vector<bool>> boolListArg) noexcept
: id { std::move(idArg) }
, testTaskState { std::move(testTaskStateArg) }
, isComplete { std::move(isCompleteArg) }
, clientMutationId { std::move(clientMutationIdArg) }
, boolList { std::move(boolListArg) }
{
}

Expand All @@ -152,6 +155,7 @@ CompleteTaskInput::CompleteTaskInput(const CompleteTaskInput& other)
, testTaskState { ModifiedVariable<TaskState>::duplicate<TypeModifier::Nullable>(other.testTaskState) }
, isComplete { ModifiedVariable<bool>::duplicate<TypeModifier::Nullable>(other.isComplete) }
, clientMutationId { ModifiedVariable<std::string>::duplicate<TypeModifier::Nullable>(other.clientMutationId) }
, boolList { ModifiedVariable<bool>::duplicate<TypeModifier::Nullable, TypeModifier::List>(other.boolList) }
{
}

Expand All @@ -160,6 +164,7 @@ CompleteTaskInput::CompleteTaskInput(CompleteTaskInput&& other) noexcept
, testTaskState { std::move(other.testTaskState) }
, isComplete { std::move(other.isComplete) }
, clientMutationId { std::move(other.clientMutationId) }
, boolList { std::move(other.boolList) }
{
}

Expand All @@ -179,6 +184,7 @@ CompleteTaskInput& CompleteTaskInput::operator=(CompleteTaskInput&& other) noexc
testTaskState = std::move(other.testTaskState);
isComplete = std::move(other.isComplete);
clientMutationId = std::move(other.clientMutationId);
boolList = std::move(other.boolList);

return *this;
}
Expand Down Expand Up @@ -2316,6 +2322,7 @@ response::Value Variable<CompleteTaskInput>::serialize(CompleteTaskInput&& input
result.emplace_back(R"js(testTaskState)js"s, ModifiedVariable<TaskState>::serialize<TypeModifier::Nullable>(std::move(inputValue.testTaskState)));
result.emplace_back(R"js(isComplete)js"s, ModifiedVariable<bool>::serialize<TypeModifier::Nullable>(std::move(inputValue.isComplete)));
result.emplace_back(R"js(clientMutationId)js"s, ModifiedVariable<std::string>::serialize<TypeModifier::Nullable>(std::move(inputValue.clientMutationId)));
result.emplace_back(R"js(boolList)js"s, ModifiedVariable<bool>::serialize<TypeModifier::Nullable, TypeModifier::List>(std::move(inputValue.boolList)));

return result;
}
Expand Down
4 changes: 3 additions & 1 deletion samples/client/multiple/MultipleQueriesClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ struct [[nodiscard("unnecessary construction")]] CompleteTaskInput
response::IdType idArg,
std::optional<TaskState> testTaskStateArg,
std::optional<bool> isCompleteArg,
std::optional<std::string> clientMutationIdArg) noexcept;
std::optional<std::string> clientMutationIdArg,
std::optional<std::vector<bool>> boolListArg) noexcept;
CompleteTaskInput(const CompleteTaskInput& other);
CompleteTaskInput(CompleteTaskInput&& other) noexcept;
~CompleteTaskInput();
Expand All @@ -144,6 +145,7 @@ struct [[nodiscard("unnecessary construction")]] CompleteTaskInput
std::optional<TaskState> testTaskState;
std::optional<bool> isComplete;
std::optional<std::string> clientMutationId;
std::optional<std::vector<bool>> boolList;
};

namespace client {
Expand Down
9 changes: 8 additions & 1 deletion samples/client/mutate/MutateClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ CompleteTaskInput::CompleteTaskInput() noexcept
, testTaskState {}
, isComplete {}
, clientMutationId {}
, boolList {}
{
// Explicit definition to prevent ODR violations when LTO is enabled.
}
Expand All @@ -72,11 +73,13 @@ CompleteTaskInput::CompleteTaskInput(
response::IdType idArg,
std::optional<TaskState> testTaskStateArg,
std::optional<bool> isCompleteArg,
std::optional<std::string> clientMutationIdArg) noexcept
std::optional<std::string> clientMutationIdArg,
std::optional<std::vector<bool>> boolListArg) noexcept
: id { std::move(idArg) }
, testTaskState { std::move(testTaskStateArg) }
, isComplete { std::move(isCompleteArg) }
, clientMutationId { std::move(clientMutationIdArg) }
, boolList { std::move(boolListArg) }
{
}

Expand All @@ -85,6 +88,7 @@ CompleteTaskInput::CompleteTaskInput(const CompleteTaskInput& other)
, testTaskState { ModifiedVariable<TaskState>::duplicate<TypeModifier::Nullable>(other.testTaskState) }
, isComplete { ModifiedVariable<bool>::duplicate<TypeModifier::Nullable>(other.isComplete) }
, clientMutationId { ModifiedVariable<std::string>::duplicate<TypeModifier::Nullable>(other.clientMutationId) }
, boolList { ModifiedVariable<bool>::duplicate<TypeModifier::Nullable, TypeModifier::List>(other.boolList) }
{
}

Expand All @@ -93,6 +97,7 @@ CompleteTaskInput::CompleteTaskInput(CompleteTaskInput&& other) noexcept
, testTaskState { std::move(other.testTaskState) }
, isComplete { std::move(other.isComplete) }
, clientMutationId { std::move(other.clientMutationId) }
, boolList { std::move(other.boolList) }
{
}

Expand All @@ -112,6 +117,7 @@ CompleteTaskInput& CompleteTaskInput::operator=(CompleteTaskInput&& other) noexc
testTaskState = std::move(other.testTaskState);
isComplete = std::move(other.isComplete);
clientMutationId = std::move(other.clientMutationId);
boolList = std::move(other.boolList);

return *this;
}
Expand Down Expand Up @@ -148,6 +154,7 @@ response::Value Variable<CompleteTaskInput>::serialize(CompleteTaskInput&& input
result.emplace_back(R"js(testTaskState)js"s, ModifiedVariable<TaskState>::serialize<TypeModifier::Nullable>(std::move(inputValue.testTaskState)));
result.emplace_back(R"js(isComplete)js"s, ModifiedVariable<bool>::serialize<TypeModifier::Nullable>(std::move(inputValue.isComplete)));
result.emplace_back(R"js(clientMutationId)js"s, ModifiedVariable<std::string>::serialize<TypeModifier::Nullable>(std::move(inputValue.clientMutationId)));
result.emplace_back(R"js(boolList)js"s, ModifiedVariable<bool>::serialize<TypeModifier::Nullable, TypeModifier::List>(std::move(inputValue.boolList)));

return result;
}
Expand Down
4 changes: 3 additions & 1 deletion samples/client/mutate/MutateClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ struct [[nodiscard("unnecessary construction")]] CompleteTaskInput
response::IdType idArg,
std::optional<TaskState> testTaskStateArg,
std::optional<bool> isCompleteArg,
std::optional<std::string> clientMutationIdArg) noexcept;
std::optional<std::string> clientMutationIdArg,
std::optional<std::vector<bool>> boolListArg) noexcept;
CompleteTaskInput(const CompleteTaskInput& other);
CompleteTaskInput(CompleteTaskInput&& other) noexcept;
~CompleteTaskInput();
Expand All @@ -77,6 +78,7 @@ struct [[nodiscard("unnecessary construction")]] CompleteTaskInput
std::optional<TaskState> testTaskState;
std::optional<bool> isComplete;
std::optional<std::string> clientMutationId;
std::optional<std::vector<bool>> boolList;
};

namespace client {
Expand Down
1 change: 1 addition & 0 deletions samples/today/schema.today.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ input CompleteTaskInput {
testTaskState: TaskState
isComplete: Boolean = true
clientMutationId: String
boolList: [Boolean!]
}

type CompleteTaskPayload {
Expand Down
3 changes: 2 additions & 1 deletion test/ClientTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ TEST_F(ClientCase, MutateCompleteTask)
{ std::make_unique<CompleteTaskInput>(CompleteTaskInput { today::getFakeTaskId(),
std::nullopt,
std::make_optional(true),
std::make_optional("Hi There!"s) }) });
std::make_optional("Hi There!"s),
std::vector<bool>({true,false}) }) });

auto state = std::make_shared<today::RequestState>(5);
auto result =
Expand Down