Skip to content
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

Merge #337 #341

Merged
merged 9 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
25 changes: 21 additions & 4 deletions include/graphqlservice/GraphQLClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,19 @@ 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> && OnlyNoneModifiers<Other...>)
{
std::ranges::for_each(listValue, [&result](bool value) {
result.emplace_back(response::Value { value });
});
}
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 @@ -219,7 +229,14 @@ struct ModifiedVariable
{
typename VariableTraits<Type, Modifier, Other...>::type result(listValue.size());

std::ranges::transform(listValue, result.begin(), duplicate<Other...>);
if constexpr (std::is_same_v<Type, bool> && OnlyNoneModifiers<Other...>)
{
std::copy(listValue.begin(), listValue.end(), result.begin());
}
else
{
std::ranges::transform(listValue, result.begin(), duplicate<Other...>);
}

return result;
}
Expand Down
9 changes: 8 additions & 1 deletion include/graphqlservice/GraphQLService.h
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,14 @@ struct ModifiedArgument
{
typename ArgumentTraits<Type, Modifier, Other...>::type result(listValue.size());

std::ranges::transform(listValue, result.begin(), duplicate<Other...>);
if constexpr (std::is_same_v<Type, bool> && OnlyNoneModifiers<Other...>)
{
std::copy(listValue.begin(), listValue.end(), result.begin());
}
else
{
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
2 changes: 1 addition & 1 deletion samples/learn/schema/StarWarsSharedTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ service::AwaitableResolver Result<learn::Episode>::convert(service::AwaitableSca
return ModifiedResult<learn::Episode>::resolve(std::move(result), std::move(params),
[](learn::Episode value, const ResolverParams&)
{
const size_t idx = static_cast<size_t>(value);
const auto idx = static_cast<size_t>(value);

if (idx >= s_namesEpisode.size())
{
Expand Down
2 changes: 1 addition & 1 deletion samples/proxy/schema/ProxySharedTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ service::AwaitableResolver Result<proxy::OperationType>::convert(service::Awaita
return ModifiedResult<proxy::OperationType>::resolve(std::move(result), std::move(params),
[](proxy::OperationType value, const ResolverParams&)
{
const size_t idx = static_cast<size_t>(value);
const auto idx = static_cast<size_t>(value);

if (idx >= s_namesOperationType.size())
{
Expand Down
3 changes: 2 additions & 1 deletion samples/today/nointrospection/TodaySchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ void AddTypesToSchema(const std::shared_ptr<schema::Schema>& schema)
schema::InputValue::Make(R"gql(id)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(ID)gql"sv)), R"gql()gql"sv),
schema::InputValue::Make(R"gql(testTaskState)gql"sv, R"md()md"sv, schema->LookupType(R"gql(TaskState)gql"sv), R"gql()gql"sv),
schema::InputValue::Make(R"gql(isComplete)gql"sv, R"md()md"sv, schema->LookupType(R"gql(Boolean)gql"sv), R"gql(true)gql"sv),
schema::InputValue::Make(R"gql(clientMutationId)gql"sv, R"md()md"sv, schema->LookupType(R"gql(String)gql"sv), R"gql()gql"sv)
schema::InputValue::Make(R"gql(clientMutationId)gql"sv, R"md()md"sv, schema->LookupType(R"gql(String)gql"sv), R"gql()gql"sv),
schema::InputValue::Make(R"gql(boolList)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::LIST, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(Boolean)gql"sv))), R"gql()gql"sv)
});
typeThirdNestedInput->AddInputValues({
schema::InputValue::Make(R"gql(id)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(ID)gql"sv)), R"gql()gql"sv),
Expand Down
14 changes: 11 additions & 3 deletions samples/today/nointrospection/TodaySharedTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ service::AwaitableResolver Result<today::TaskState>::convert(service::AwaitableS
return ModifiedResult<today::TaskState>::resolve(std::move(result), std::move(params),
[](today::TaskState value, const ResolverParams&)
{
const size_t idx = static_cast<size_t>(value);
const auto idx = static_cast<size_t>(value);

if (idx >= s_namesTaskState.size())
{
Expand Down Expand Up @@ -101,12 +101,14 @@ today::CompleteTaskInput Argument<today::CompleteTaskInput>::convert(const respo
? std::move(pairIsComplete.first)
: service::ModifiedArgument<bool>::require<service::TypeModifier::Nullable>("isComplete", defaultValue));
auto valueClientMutationId = service::ModifiedArgument<std::string>::require<service::TypeModifier::Nullable>("clientMutationId", value);
auto valueBoolList = service::ModifiedArgument<bool>::require<service::TypeModifier::Nullable, service::TypeModifier::List>("boolList", value);

return today::CompleteTaskInput {
std::move(valueId),
valueTestTaskState,
std::move(valueIsComplete),
std::move(valueClientMutationId)
std::move(valueClientMutationId),
std::move(valueBoolList)
};
}

Expand Down Expand Up @@ -231,6 +233,7 @@ CompleteTaskInput::CompleteTaskInput() noexcept
, testTaskState {}
, isComplete {}
, clientMutationId {}
, boolList {}
{
// Explicit definition to prevent ODR violations when LTO is enabled.
}
Expand All @@ -239,11 +242,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 @@ -252,6 +257,7 @@ CompleteTaskInput::CompleteTaskInput(const CompleteTaskInput& other)
, testTaskState { service::ModifiedArgument<TaskState>::duplicate<service::TypeModifier::Nullable>(other.testTaskState) }
, isComplete { service::ModifiedArgument<bool>::duplicate<service::TypeModifier::Nullable>(other.isComplete) }
, clientMutationId { service::ModifiedArgument<std::string>::duplicate<service::TypeModifier::Nullable>(other.clientMutationId) }
, boolList { service::ModifiedArgument<bool>::duplicate<service::TypeModifier::Nullable, service::TypeModifier::List>(other.boolList) }
{
}

Expand All @@ -260,6 +266,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 @@ -283,6 +290,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
4 changes: 3 additions & 1 deletion samples/today/nointrospection/TodaySharedTypes.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;
};

struct SecondNestedInput;
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 samples/today/schema/TodaySchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ void AddTypesToSchema(const std::shared_ptr<schema::Schema>& schema)
schema::InputValue::Make(R"gql(id)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(ID)gql"sv)), R"gql()gql"sv),
schema::InputValue::Make(R"gql(testTaskState)gql"sv, R"md()md"sv, schema->LookupType(R"gql(TaskState)gql"sv), R"gql()gql"sv),
schema::InputValue::Make(R"gql(isComplete)gql"sv, R"md()md"sv, schema->LookupType(R"gql(Boolean)gql"sv), R"gql(true)gql"sv),
schema::InputValue::Make(R"gql(clientMutationId)gql"sv, R"md()md"sv, schema->LookupType(R"gql(String)gql"sv), R"gql()gql"sv)
schema::InputValue::Make(R"gql(clientMutationId)gql"sv, R"md()md"sv, schema->LookupType(R"gql(String)gql"sv), R"gql()gql"sv),
schema::InputValue::Make(R"gql(boolList)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::LIST, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(Boolean)gql"sv))), R"gql()gql"sv)
});
typeThirdNestedInput->AddInputValues({
schema::InputValue::Make(R"gql(id)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(ID)gql"sv)), R"gql()gql"sv),
Expand Down
Loading