From e216334e4543d00ca5300a5e7a9abbed4df0b0e0 Mon Sep 17 00:00:00 2001 From: Bill Avery Date: Thu, 19 Sep 2024 11:31:32 -0700 Subject: [PATCH 1/4] feat(sharetypes): rearrange namespaces so they can overlap --- samples/client/benchmark.cpp | 2 +- samples/client/benchmark/BenchmarkClient.cpp | 41 ++-- samples/client/benchmark/BenchmarkClient.h | 21 +-- samples/client/benchmark/BenchmarkClient.ixx | 17 +- .../client/multiple/MultipleQueriesClient.cpp | 148 +++++++++------ .../client/multiple/MultipleQueriesClient.h | 45 ++--- .../client/multiple/MultipleQueriesClient.ixx | 41 ++-- samples/client/mutate/MutateClient.cpp | 35 ++-- samples/client/mutate/MutateClient.h | 27 +-- samples/client/mutate/MutateClient.ixx | 23 ++- .../client/nestedinput/NestedInputClient.cpp | 35 ++-- .../client/nestedinput/NestedInputClient.h | 31 +-- .../client/nestedinput/NestedInputClient.ixx | 27 +-- samples/client/query/QueryClient.cpp | 72 +++---- samples/client/query/QueryClient.h | 25 +-- samples/client/query/QueryClient.ixx | 21 ++- samples/client/subscribe/SubscribeClient.cpp | 23 ++- samples/client/subscribe/SubscribeClient.h | 21 +-- samples/client/subscribe/SubscribeClient.ixx | 17 +- samples/proxy/client.cpp | 5 +- samples/proxy/query/ProxyClient.cpp | 25 ++- samples/proxy/query/ProxyClient.h | 21 +-- samples/proxy/query/ProxyClient.ixx | 17 +- src/ClientGenerator.cpp | 178 +++++++++++++----- test/ClientTests.cpp | 8 +- 25 files changed, 558 insertions(+), 368 deletions(-) diff --git a/samples/client/benchmark.cpp b/samples/client/benchmark.cpp index 73ce8780..bd699ea8 100644 --- a/samples/client/benchmark.cpp +++ b/samples/client/benchmark.cpp @@ -93,7 +93,7 @@ int main(int argc, char** argv) try { - using namespace client::query::Query; + using namespace benchmark::client::query::Query; auto query = GetRequestObject(); const auto& name = GetOperationName(); diff --git a/samples/client/benchmark/BenchmarkClient.cpp b/samples/client/benchmark/BenchmarkClient.cpp index 5a7e346b..0f9fb48b 100644 --- a/samples/client/benchmark/BenchmarkClient.cpp +++ b/samples/client/benchmark/BenchmarkClient.cpp @@ -16,8 +16,9 @@ using namespace std::literals; -namespace graphql::client { +namespace graphql { namespace benchmark { +namespace client { const std::string& GetRequestText() noexcept { @@ -59,14 +60,16 @@ const peg::ast& GetRequestObject() noexcept return s_request; } +} // namespace client } // namespace benchmark +namespace client { using namespace benchmark; template <> -query::Query::Response::appointments_AppointmentConnection::pageInfo_PageInfo Response::parse(response::Value&& response) +graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection::pageInfo_PageInfo Response::parse(response::Value&& response) { - query::Query::Response::appointments_AppointmentConnection::pageInfo_PageInfo result; + graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection::pageInfo_PageInfo result; if (response.type() == response::Type::Map) { @@ -86,9 +89,9 @@ query::Query::Response::appointments_AppointmentConnection::pageInfo_PageInfo Re } template <> -query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment Response::parse(response::Value&& response) +graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment Response::parse(response::Value&& response) { - query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment result; + graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment result; if (response.type() == response::Type::Map) { @@ -123,9 +126,9 @@ query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdg } template <> -query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge Response::parse(response::Value&& response) +graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge Response::parse(response::Value&& response) { - query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge result; + graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge result; if (response.type() == response::Type::Map) { @@ -135,7 +138,7 @@ query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdg { if (member.first == R"js(node)js"sv) { - result.node = ModifiedResponse::parse(std::move(member.second)); + result.node = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -145,9 +148,9 @@ query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdg } template <> -query::Query::Response::appointments_AppointmentConnection Response::parse(response::Value&& response) +graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection Response::parse(response::Value&& response) { - query::Query::Response::appointments_AppointmentConnection result; + graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection result; if (response.type() == response::Type::Map) { @@ -157,12 +160,12 @@ query::Query::Response::appointments_AppointmentConnection Response::parse(std::move(member.second)); + result.pageInfo = ModifiedResponse::parse(std::move(member.second)); continue; } if (member.first == R"js(edges)js"sv) { - result.edges = ModifiedResponse::parse(std::move(member.second)); + result.edges = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -171,7 +174,9 @@ query::Query::Response::appointments_AppointmentConnection Response -/// Operation: query (unnamed) -/// -/// +/// # Operation: query (unnamed) +/// ```graphql /// # Copyright (c) Microsoft Corporation. All rights reserved. /// # Licensed under the MIT License. /// @@ -46,8 +44,8 @@ namespace graphql::client { /// } /// } /// } -/// -namespace benchmark { +/// ``` +namespace client { // Return the original text of the request document. [[nodiscard("unnecessary call")]] const std::string& GetRequestText() noexcept; @@ -55,12 +53,10 @@ namespace benchmark { // Return a pre-parsed, pre-validated request object. [[nodiscard("unnecessary call")]] const peg::ast& GetRequestObject() noexcept; -} // namespace benchmark - namespace query::Query { -using benchmark::GetRequestText; -using benchmark::GetRequestObject; +using graphql::benchmark::client::GetRequestText; +using graphql::benchmark::client::GetRequestObject; // Return the name of this operation in the shared request document. [[nodiscard("unnecessary call")]] const std::string& GetOperationName() noexcept; @@ -108,6 +104,7 @@ struct Traits }; } // namespace query::Query -} // namespace graphql::client +} // namespace client +} // namespace graphql::benchmark #endif // BENCHMARKCLIENT_H diff --git a/samples/client/benchmark/BenchmarkClient.ixx b/samples/client/benchmark/BenchmarkClient.ixx index 0400cf83..4ab91474 100644 --- a/samples/client/benchmark/BenchmarkClient.ixx +++ b/samples/client/benchmark/BenchmarkClient.ixx @@ -9,19 +9,17 @@ module; export module GraphQL.Benchmark.BenchmarkClient; -export namespace graphql::client { +export namespace graphql::benchmark { -namespace benchmark { +namespace client { -using benchmark::GetRequestText; -using benchmark::GetRequestObject; - -} // namespace benchmark +using client::GetRequestText; +using client::GetRequestObject; namespace query::Query { -using benchmark::GetRequestText; -using benchmark::GetRequestObject; +using graphql::benchmark::client::GetRequestText; +using graphql::benchmark::client::GetRequestObject; using Query::GetOperationName; using Query::Response; @@ -31,4 +29,5 @@ using Query::Traits; } // namespace query::Query -} // namespace graphql::client +} // namespace client +} // namespace graphql::benchmark diff --git a/samples/client/multiple/MultipleQueriesClient.cpp b/samples/client/multiple/MultipleQueriesClient.cpp index 3b5d533f..92959f11 100644 --- a/samples/client/multiple/MultipleQueriesClient.cpp +++ b/samples/client/multiple/MultipleQueriesClient.cpp @@ -16,8 +16,9 @@ using namespace std::literals; -namespace graphql::client { +namespace graphql { namespace multiple { +namespace client { const std::string& GetRequestText() noexcept { @@ -121,6 +122,10 @@ const peg::ast& GetRequestObject() noexcept return s_request; } +} // namespace client + +using namespace graphql::client; + CompleteTaskInput::CompleteTaskInput() noexcept : id {} , testTaskState {} @@ -179,13 +184,14 @@ CompleteTaskInput& CompleteTaskInput::operator=(CompleteTaskInput&& other) noexc } } // namespace multiple +namespace client { using namespace multiple; template <> -query::Appointments::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment Response::parse(response::Value&& response) +graphql::multiple::client::query::Appointments::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment Response::parse(response::Value&& response) { - query::Appointments::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment result; + graphql::multiple::client::query::Appointments::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment result; if (response.type() == response::Type::Map) { @@ -225,9 +231,9 @@ query::Appointments::Response::appointments_AppointmentConnection::edges_Appoint } template <> -query::Appointments::Response::appointments_AppointmentConnection::edges_AppointmentEdge Response::parse(response::Value&& response) +graphql::multiple::client::query::Appointments::Response::appointments_AppointmentConnection::edges_AppointmentEdge Response::parse(response::Value&& response) { - query::Appointments::Response::appointments_AppointmentConnection::edges_AppointmentEdge result; + graphql::multiple::client::query::Appointments::Response::appointments_AppointmentConnection::edges_AppointmentEdge result; if (response.type() == response::Type::Map) { @@ -237,7 +243,7 @@ query::Appointments::Response::appointments_AppointmentConnection::edges_Appoint { if (member.first == R"js(node)js"sv) { - result.node = ModifiedResponse::parse(std::move(member.second)); + result.node = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -247,9 +253,9 @@ query::Appointments::Response::appointments_AppointmentConnection::edges_Appoint } template <> -query::Appointments::Response::appointments_AppointmentConnection Response::parse(response::Value&& response) +graphql::multiple::client::query::Appointments::Response::appointments_AppointmentConnection Response::parse(response::Value&& response) { - query::Appointments::Response::appointments_AppointmentConnection result; + graphql::multiple::client::query::Appointments::Response::appointments_AppointmentConnection result; if (response.type() == response::Type::Map) { @@ -259,7 +265,7 @@ query::Appointments::Response::appointments_AppointmentConnection Response::parse(std::move(member.second)); + result.edges = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -268,7 +274,9 @@ query::Appointments::Response::appointments_AppointmentConnection Response -query::Tasks::Response::tasks_TaskConnection::edges_TaskEdge::node_Task Response::parse(response::Value&& response) +graphql::multiple::client::query::Tasks::Response::tasks_TaskConnection::edges_TaskEdge::node_Task Response::parse(response::Value&& response) { - query::Tasks::Response::tasks_TaskConnection::edges_TaskEdge::node_Task result; + graphql::multiple::client::query::Tasks::Response::tasks_TaskConnection::edges_TaskEdge::node_Task result; if (response.type() == response::Type::Map) { @@ -358,9 +371,9 @@ query::Tasks::Response::tasks_TaskConnection::edges_TaskEdge::node_Task Response } template <> -query::Tasks::Response::tasks_TaskConnection::edges_TaskEdge Response::parse(response::Value&& response) +graphql::multiple::client::query::Tasks::Response::tasks_TaskConnection::edges_TaskEdge Response::parse(response::Value&& response) { - query::Tasks::Response::tasks_TaskConnection::edges_TaskEdge result; + graphql::multiple::client::query::Tasks::Response::tasks_TaskConnection::edges_TaskEdge result; if (response.type() == response::Type::Map) { @@ -370,7 +383,7 @@ query::Tasks::Response::tasks_TaskConnection::edges_TaskEdge Response::parse(std::move(member.second)); + result.node = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -380,9 +393,9 @@ query::Tasks::Response::tasks_TaskConnection::edges_TaskEdge Response -query::Tasks::Response::tasks_TaskConnection Response::parse(response::Value&& response) +graphql::multiple::client::query::Tasks::Response::tasks_TaskConnection Response::parse(response::Value&& response) { - query::Tasks::Response::tasks_TaskConnection result; + graphql::multiple::client::query::Tasks::Response::tasks_TaskConnection result; if (response.type() == response::Type::Map) { @@ -392,7 +405,7 @@ query::Tasks::Response::tasks_TaskConnection Response::parse(std::move(member.second)); + result.edges = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -401,7 +414,9 @@ query::Tasks::Response::tasks_TaskConnection Response -query::UnreadCounts::Response::unreadCounts_FolderConnection::edges_FolderEdge::node_Folder Response::parse(response::Value&& response) +graphql::multiple::client::query::UnreadCounts::Response::unreadCounts_FolderConnection::edges_FolderEdge::node_Folder Response::parse(response::Value&& response) { - query::UnreadCounts::Response::unreadCounts_FolderConnection::edges_FolderEdge::node_Folder result; + graphql::multiple::client::query::UnreadCounts::Response::unreadCounts_FolderConnection::edges_FolderEdge::node_Folder result; if (response.type() == response::Type::Map) { @@ -491,9 +511,9 @@ query::UnreadCounts::Response::unreadCounts_FolderConnection::edges_FolderEdge:: } template <> -query::UnreadCounts::Response::unreadCounts_FolderConnection::edges_FolderEdge Response::parse(response::Value&& response) +graphql::multiple::client::query::UnreadCounts::Response::unreadCounts_FolderConnection::edges_FolderEdge Response::parse(response::Value&& response) { - query::UnreadCounts::Response::unreadCounts_FolderConnection::edges_FolderEdge result; + graphql::multiple::client::query::UnreadCounts::Response::unreadCounts_FolderConnection::edges_FolderEdge result; if (response.type() == response::Type::Map) { @@ -503,7 +523,7 @@ query::UnreadCounts::Response::unreadCounts_FolderConnection::edges_FolderEdge R { if (member.first == R"js(node)js"sv) { - result.node = ModifiedResponse::parse(std::move(member.second)); + result.node = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -513,9 +533,9 @@ query::UnreadCounts::Response::unreadCounts_FolderConnection::edges_FolderEdge R } template <> -query::UnreadCounts::Response::unreadCounts_FolderConnection Response::parse(response::Value&& response) +graphql::multiple::client::query::UnreadCounts::Response::unreadCounts_FolderConnection Response::parse(response::Value&& response) { - query::UnreadCounts::Response::unreadCounts_FolderConnection result; + graphql::multiple::client::query::UnreadCounts::Response::unreadCounts_FolderConnection result; if (response.type() == response::Type::Map) { @@ -525,7 +545,7 @@ query::UnreadCounts::Response::unreadCounts_FolderConnection Response::parse(std::move(member.second)); + result.edges = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -534,7 +554,9 @@ query::UnreadCounts::Response::unreadCounts_FolderConnection Response TaskState Response::parse(response::Value&& value) @@ -614,9 +642,9 @@ TaskState Response::parse(response::Value&& value) } template <> -query::Miscellaneous::Response::anyType_UnionType Response::parse(response::Value&& response) +graphql::multiple::client::query::Miscellaneous::Response::anyType_UnionType Response::parse(response::Value&& response) { - query::Miscellaneous::Response::anyType_UnionType result; + graphql::multiple::client::query::Miscellaneous::Response::anyType_UnionType result; if (response.type() == response::Type::Map) { @@ -665,7 +693,9 @@ query::Miscellaneous::Response::anyType_UnionType Response response::Value Variable::serialize(TaskState&& value) @@ -758,9 +794,9 @@ response::Value Variable::serialize(CompleteTaskInput&& input } template <> -mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload::completedTask_Task Response::parse(response::Value&& response) +graphql::multiple::client::mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload::completedTask_Task Response::parse(response::Value&& response) { - mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload::completedTask_Task result; + graphql::multiple::client::mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload::completedTask_Task result; if (response.type() == response::Type::Map) { @@ -790,9 +826,9 @@ mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload::com } template <> -mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload Response::parse(response::Value&& response) +graphql::multiple::client::mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload Response::parse(response::Value&& response) { - mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload result; + graphql::multiple::client::mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload result; if (response.type() == response::Type::Map) { @@ -802,7 +838,7 @@ mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload Resp { if (member.first == R"js(completedTask)js"sv) { - result.completedTask = ModifiedResponse::parse(std::move(member.second)); + result.completedTask = ModifiedResponse::parse(std::move(member.second)); continue; } if (member.first == R"js(clientMutationId)js"sv) @@ -816,7 +852,9 @@ mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload Resp return result; } -namespace mutation::CompleteTaskMutation { +} // namespace client + +namespace multiple::client::mutation::CompleteTaskMutation { const std::string& GetOperationName() noexcept { @@ -827,6 +865,8 @@ const std::string& GetOperationName() noexcept response::Value serializeVariables(Variables&& variables) { + using namespace graphql::client; + response::Value result { response::Type::Map }; result.emplace_back(R"js(input)js"s, ModifiedVariable::serialize(std::move(variables.input))); @@ -837,6 +877,8 @@ response::Value serializeVariables(Variables&& variables) Response parseResponse(response::Value&& response) { + using namespace graphql::client; + Response result; if (response.type() == response::Type::Map) @@ -858,12 +900,12 @@ Response parseResponse(response::Value&& response) [[nodiscard("unnecessary call")]] const std::string& Traits::GetRequestText() noexcept { - return multiple::GetRequestText(); + return client::GetRequestText(); } [[nodiscard("unnecessary call")]] const peg::ast& Traits::GetRequestObject() noexcept { - return multiple::GetRequestObject(); + return client::GetRequestObject(); } [[nodiscard("unnecessary call")]] const std::string& Traits::GetOperationName() noexcept @@ -881,5 +923,5 @@ Response parseResponse(response::Value&& response) return CompleteTaskMutation::parseResponse(std::move(response)); } -} // namespace mutation::CompleteTaskMutation -} // namespace graphql::client +} // namespace multiple::client::mutation::CompleteTaskMutation +} // namespace graphql diff --git a/samples/client/multiple/MultipleQueriesClient.h b/samples/client/multiple/MultipleQueriesClient.h index 4e3e7634..8806bec7 100644 --- a/samples/client/multiple/MultipleQueriesClient.h +++ b/samples/client/multiple/MultipleQueriesClient.h @@ -22,12 +22,10 @@ static_assert(graphql::internal::MajorVersion == 5, "regenerate with clientgen: major version mismatch"); static_assert(graphql::internal::MinorVersion == 0, "regenerate with clientgen: minor version mismatch"); -namespace graphql::client { +namespace graphql::multiple { -/// -/// Operations: query Appointments, query Tasks, query UnreadCounts, query Miscellaneous, mutation CompleteTaskMutation -/// -/// +/// # Operations: query Appointments, query Tasks, query UnreadCounts, query Miscellaneous, mutation CompleteTaskMutation +/// ```graphql /// # Copyright (c) Microsoft Corporation. All rights reserved. /// # Licensed under the MIT License. /// @@ -108,8 +106,8 @@ namespace graphql::client { /// clientMutationId @skip(if: $skipClientMutationId) /// } /// } -/// -namespace multiple { +/// ``` +namespace client { // Return the original text of the request document. [[nodiscard("unnecessary call")]] const std::string& GetRequestText() noexcept; @@ -117,6 +115,8 @@ namespace multiple { // Return a pre-parsed, pre-validated request object. [[nodiscard("unnecessary call")]] const peg::ast& GetRequestObject() noexcept; +} // namespace client + enum class [[nodiscard("unnecessary conversion")]] TaskState { Unassigned, @@ -146,12 +146,12 @@ struct [[nodiscard("unnecessary construction")]] CompleteTaskInput std::optional clientMutationId; }; -} // namespace multiple +namespace client { namespace query::Appointments { -using multiple::GetRequestText; -using multiple::GetRequestObject; +using graphql::multiple::client::GetRequestText; +using graphql::multiple::client::GetRequestObject; // Return the name of this operation in the shared request document. [[nodiscard("unnecessary call")]] const std::string& GetOperationName() noexcept; @@ -197,8 +197,8 @@ struct Traits namespace query::Tasks { -using multiple::GetRequestText; -using multiple::GetRequestObject; +using graphql::multiple::client::GetRequestText; +using graphql::multiple::client::GetRequestObject; // Return the name of this operation in the shared request document. [[nodiscard("unnecessary call")]] const std::string& GetOperationName() noexcept; @@ -243,8 +243,8 @@ struct Traits namespace query::UnreadCounts { -using multiple::GetRequestText; -using multiple::GetRequestObject; +using graphql::multiple::client::GetRequestText; +using graphql::multiple::client::GetRequestObject; // Return the name of this operation in the shared request document. [[nodiscard("unnecessary call")]] const std::string& GetOperationName() noexcept; @@ -289,13 +289,13 @@ struct Traits namespace query::Miscellaneous { -using multiple::GetRequestText; -using multiple::GetRequestObject; +using graphql::multiple::client::GetRequestText; +using graphql::multiple::client::GetRequestObject; // Return the name of this operation in the shared request document. [[nodiscard("unnecessary call")]] const std::string& GetOperationName() noexcept; -using multiple::TaskState; +using graphql::multiple::TaskState; struct [[nodiscard("unnecessary construction")]] Response { @@ -332,15 +332,15 @@ struct Traits namespace mutation::CompleteTaskMutation { -using multiple::GetRequestText; -using multiple::GetRequestObject; +using graphql::multiple::client::GetRequestText; +using graphql::multiple::client::GetRequestObject; // Return the name of this operation in the shared request document. [[nodiscard("unnecessary call")]] const std::string& GetOperationName() noexcept; -using multiple::TaskState; +using graphql::multiple::TaskState; -using multiple::CompleteTaskInput; +using graphql::multiple::CompleteTaskInput; struct [[nodiscard("unnecessary construction")]] Variables { @@ -386,6 +386,7 @@ struct Traits }; } // namespace mutation::CompleteTaskMutation -} // namespace graphql::client +} // namespace client +} // namespace graphql::multiple #endif // MULTIPLEQUERIESCLIENT_H diff --git a/samples/client/multiple/MultipleQueriesClient.ixx b/samples/client/multiple/MultipleQueriesClient.ixx index a12ea9b4..d21f7130 100644 --- a/samples/client/multiple/MultipleQueriesClient.ixx +++ b/samples/client/multiple/MultipleQueriesClient.ixx @@ -9,23 +9,25 @@ module; export module GraphQL.MultipleQueries.MultipleQueriesClient; -export namespace graphql::client { +export namespace graphql::multiple { -namespace multiple { +namespace client { -using multiple::GetRequestText; -using multiple::GetRequestObject; +using client::GetRequestText; +using client::GetRequestObject; + +} // namespace client using multiple::TaskState; using multiple::CompleteTaskInput; -} // namespace multiple +namespace client { namespace query::Appointments { -using multiple::GetRequestText; -using multiple::GetRequestObject; +using graphql::multiple::client::GetRequestText; +using graphql::multiple::client::GetRequestObject; using Appointments::GetOperationName; using Appointments::Response; @@ -37,8 +39,8 @@ using Appointments::Traits; namespace query::Tasks { -using multiple::GetRequestText; -using multiple::GetRequestObject; +using graphql::multiple::client::GetRequestText; +using graphql::multiple::client::GetRequestObject; using Tasks::GetOperationName; using Tasks::Response; @@ -50,8 +52,8 @@ using Tasks::Traits; namespace query::UnreadCounts { -using multiple::GetRequestText; -using multiple::GetRequestObject; +using graphql::multiple::client::GetRequestText; +using graphql::multiple::client::GetRequestObject; using UnreadCounts::GetOperationName; using UnreadCounts::Response; @@ -63,11 +65,11 @@ using UnreadCounts::Traits; namespace query::Miscellaneous { -using multiple::GetRequestText; -using multiple::GetRequestObject; +using graphql::multiple::client::GetRequestText; +using graphql::multiple::client::GetRequestObject; using Miscellaneous::GetOperationName; -using multiple::TaskState; +using graphql::multiple::TaskState; using Miscellaneous::Response; using Miscellaneous::parseResponse; @@ -78,13 +80,13 @@ using Miscellaneous::Traits; namespace mutation::CompleteTaskMutation { -using multiple::GetRequestText; -using multiple::GetRequestObject; +using graphql::multiple::client::GetRequestText; +using graphql::multiple::client::GetRequestObject; using CompleteTaskMutation::GetOperationName; -using multiple::TaskState; +using graphql::multiple::TaskState; -using multiple::CompleteTaskInput; +using graphql::multiple::CompleteTaskInput; using CompleteTaskMutation::Variables; using CompleteTaskMutation::serializeVariables; @@ -96,4 +98,5 @@ using CompleteTaskMutation::Traits; } // namespace mutation::CompleteTaskMutation -} // namespace graphql::client +} // namespace client +} // namespace graphql::multiple diff --git a/samples/client/mutate/MutateClient.cpp b/samples/client/mutate/MutateClient.cpp index 8db8bd6a..a0f26f85 100644 --- a/samples/client/mutate/MutateClient.cpp +++ b/samples/client/mutate/MutateClient.cpp @@ -16,8 +16,9 @@ using namespace std::literals; -namespace graphql::client { +namespace graphql { namespace mutate { +namespace client { const std::string& GetRequestText() noexcept { @@ -54,6 +55,10 @@ const peg::ast& GetRequestObject() noexcept return s_request; } +} // namespace client + +using namespace graphql::client; + CompleteTaskInput::CompleteTaskInput() noexcept : id {} , testTaskState {} @@ -113,6 +118,8 @@ CompleteTaskInput& CompleteTaskInput::operator=(CompleteTaskInput&& other) noexc } // namespace mutate +namespace client { + using namespace mutate; template <> @@ -173,9 +180,9 @@ TaskState Response::parse(response::Value&& value) } template <> -mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload::completedTask_Task Response::parse(response::Value&& response) +graphql::mutate::client::mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload::completedTask_Task Response::parse(response::Value&& response) { - mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload::completedTask_Task result; + graphql::mutate::client::mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload::completedTask_Task result; if (response.type() == response::Type::Map) { @@ -205,9 +212,9 @@ mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload::com } template <> -mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload Response::parse(response::Value&& response) +graphql::mutate::client::mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload Response::parse(response::Value&& response) { - mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload result; + graphql::mutate::client::mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload result; if (response.type() == response::Type::Map) { @@ -217,7 +224,7 @@ mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload Resp { if (member.first == R"js(completedTask)js"sv) { - result.completedTask = ModifiedResponse::parse(std::move(member.second)); + result.completedTask = ModifiedResponse::parse(std::move(member.second)); continue; } if (member.first == R"js(clientMutationId)js"sv) @@ -231,7 +238,9 @@ mutation::CompleteTaskMutation::Response::completedTask_CompleteTaskPayload Resp return result; } -namespace mutation::CompleteTaskMutation { +} // namespace client + +namespace mutate::client::mutation::CompleteTaskMutation { const std::string& GetOperationName() noexcept { @@ -242,6 +251,8 @@ const std::string& GetOperationName() noexcept response::Value serializeVariables(Variables&& variables) { + using namespace graphql::client; + response::Value result { response::Type::Map }; result.emplace_back(R"js(input)js"s, ModifiedVariable::serialize(std::move(variables.input))); @@ -252,6 +263,8 @@ response::Value serializeVariables(Variables&& variables) Response parseResponse(response::Value&& response) { + using namespace graphql::client; + Response result; if (response.type() == response::Type::Map) @@ -273,12 +286,12 @@ Response parseResponse(response::Value&& response) [[nodiscard("unnecessary call")]] const std::string& Traits::GetRequestText() noexcept { - return mutate::GetRequestText(); + return client::GetRequestText(); } [[nodiscard("unnecessary call")]] const peg::ast& Traits::GetRequestObject() noexcept { - return mutate::GetRequestObject(); + return client::GetRequestObject(); } [[nodiscard("unnecessary call")]] const std::string& Traits::GetOperationName() noexcept @@ -296,5 +309,5 @@ Response parseResponse(response::Value&& response) return CompleteTaskMutation::parseResponse(std::move(response)); } -} // namespace mutation::CompleteTaskMutation -} // namespace graphql::client +} // namespace mutate::client::mutation::CompleteTaskMutation +} // namespace graphql diff --git a/samples/client/mutate/MutateClient.h b/samples/client/mutate/MutateClient.h index 74870657..ab016aaa 100644 --- a/samples/client/mutate/MutateClient.h +++ b/samples/client/mutate/MutateClient.h @@ -22,12 +22,10 @@ static_assert(graphql::internal::MajorVersion == 5, "regenerate with clientgen: major version mismatch"); static_assert(graphql::internal::MinorVersion == 0, "regenerate with clientgen: minor version mismatch"); -namespace graphql::client { +namespace graphql::mutate { -/// -/// Operation: mutation CompleteTaskMutation -/// -/// +/// # Operation: mutation CompleteTaskMutation +/// ```graphql /// # Copyright (c) Microsoft Corporation. All rights reserved. /// # Licensed under the MIT License. /// @@ -41,8 +39,8 @@ namespace graphql::client { /// clientMutationId @skip(if: $skipClientMutationId) /// } /// } -/// -namespace mutate { +/// ``` +namespace client { // Return the original text of the request document. [[nodiscard("unnecessary call")]] const std::string& GetRequestText() noexcept; @@ -50,6 +48,8 @@ namespace mutate { // Return a pre-parsed, pre-validated request object. [[nodiscard("unnecessary call")]] const peg::ast& GetRequestObject() noexcept; +} // namespace client + enum class [[nodiscard("unnecessary conversion")]] TaskState { Unassigned, @@ -79,19 +79,19 @@ struct [[nodiscard("unnecessary construction")]] CompleteTaskInput std::optional clientMutationId; }; -} // namespace mutate +namespace client { namespace mutation::CompleteTaskMutation { -using mutate::GetRequestText; -using mutate::GetRequestObject; +using graphql::mutate::client::GetRequestText; +using graphql::mutate::client::GetRequestObject; // Return the name of this operation in the shared request document. [[nodiscard("unnecessary call")]] const std::string& GetOperationName() noexcept; -using mutate::TaskState; +using graphql::mutate::TaskState; -using mutate::CompleteTaskInput; +using graphql::mutate::CompleteTaskInput; struct [[nodiscard("unnecessary construction")]] Variables { @@ -137,6 +137,7 @@ struct Traits }; } // namespace mutation::CompleteTaskMutation -} // namespace graphql::client +} // namespace client +} // namespace graphql::mutate #endif // MUTATECLIENT_H diff --git a/samples/client/mutate/MutateClient.ixx b/samples/client/mutate/MutateClient.ixx index 67b20b6d..4e781529 100644 --- a/samples/client/mutate/MutateClient.ixx +++ b/samples/client/mutate/MutateClient.ixx @@ -9,28 +9,30 @@ module; export module GraphQL.Mutate.MutateClient; -export namespace graphql::client { +export namespace graphql::mutate { -namespace mutate { +namespace client { -using mutate::GetRequestText; -using mutate::GetRequestObject; +using client::GetRequestText; +using client::GetRequestObject; + +} // namespace client using mutate::TaskState; using mutate::CompleteTaskInput; -} // namespace mutate +namespace client { namespace mutation::CompleteTaskMutation { -using mutate::GetRequestText; -using mutate::GetRequestObject; +using graphql::mutate::client::GetRequestText; +using graphql::mutate::client::GetRequestObject; using CompleteTaskMutation::GetOperationName; -using mutate::TaskState; +using graphql::mutate::TaskState; -using mutate::CompleteTaskInput; +using graphql::mutate::CompleteTaskInput; using CompleteTaskMutation::Variables; using CompleteTaskMutation::serializeVariables; @@ -42,4 +44,5 @@ using CompleteTaskMutation::Traits; } // namespace mutation::CompleteTaskMutation -} // namespace graphql::client +} // namespace client +} // namespace graphql::mutate diff --git a/samples/client/nestedinput/NestedInputClient.cpp b/samples/client/nestedinput/NestedInputClient.cpp index 8de48529..a70c79ba 100644 --- a/samples/client/nestedinput/NestedInputClient.cpp +++ b/samples/client/nestedinput/NestedInputClient.cpp @@ -16,8 +16,9 @@ using namespace std::literals; -namespace graphql::client { +namespace graphql { namespace nestedinput { +namespace client { const std::string& GetRequestText() noexcept { @@ -48,6 +49,10 @@ const peg::ast& GetRequestObject() noexcept return s_request; } +} // namespace client + +using namespace graphql::client; + InputA::InputA() noexcept : a {} { @@ -236,6 +241,8 @@ InputBC& InputBC::operator=(InputBC&& other) noexcept } // namespace nestedinput +namespace client { + using namespace nestedinput; template <> @@ -284,9 +291,9 @@ response::Value Variable::serialize(InputBC&& inputValue) } template <> -query::testQuery::Response::control_Control::test_Output Response::parse(response::Value&& response) +graphql::nestedinput::client::query::testQuery::Response::control_Control::test_Output Response::parse(response::Value&& response) { - query::testQuery::Response::control_Control::test_Output result; + graphql::nestedinput::client::query::testQuery::Response::control_Control::test_Output result; if (response.type() == response::Type::Map) { @@ -306,9 +313,9 @@ query::testQuery::Response::control_Control::test_Output Response -query::testQuery::Response::control_Control Response::parse(response::Value&& response) +graphql::nestedinput::client::query::testQuery::Response::control_Control Response::parse(response::Value&& response) { - query::testQuery::Response::control_Control result; + graphql::nestedinput::client::query::testQuery::Response::control_Control result; if (response.type() == response::Type::Map) { @@ -318,7 +325,7 @@ query::testQuery::Response::control_Control Response::parse(std::move(member.second)); + result.test = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -327,7 +334,9 @@ query::testQuery::Response::control_Control Response::serialize(std::move(variables.stream))); @@ -347,6 +358,8 @@ response::Value serializeVariables(Variables&& variables) Response parseResponse(response::Value&& response) { + using namespace graphql::client; + Response result; if (response.type() == response::Type::Map) @@ -368,12 +381,12 @@ Response parseResponse(response::Value&& response) [[nodiscard("unnecessary call")]] const std::string& Traits::GetRequestText() noexcept { - return nestedinput::GetRequestText(); + return client::GetRequestText(); } [[nodiscard("unnecessary call")]] const peg::ast& Traits::GetRequestObject() noexcept { - return nestedinput::GetRequestObject(); + return client::GetRequestObject(); } [[nodiscard("unnecessary call")]] const std::string& Traits::GetOperationName() noexcept @@ -391,5 +404,5 @@ Response parseResponse(response::Value&& response) return testQuery::parseResponse(std::move(response)); } -} // namespace query::testQuery -} // namespace graphql::client +} // namespace nestedinput::client::query::testQuery +} // namespace graphql diff --git a/samples/client/nestedinput/NestedInputClient.h b/samples/client/nestedinput/NestedInputClient.h index 8a1cf0eb..2350eb51 100644 --- a/samples/client/nestedinput/NestedInputClient.h +++ b/samples/client/nestedinput/NestedInputClient.h @@ -22,12 +22,10 @@ static_assert(graphql::internal::MajorVersion == 5, "regenerate with clientgen: major version mismatch"); static_assert(graphql::internal::MinorVersion == 0, "regenerate with clientgen: minor version mismatch"); -namespace graphql::client { +namespace graphql::nestedinput { -/// -/// Operation: query testQuery -/// -/// +/// # Operation: query testQuery +/// ```graphql /// query testQuery($stream: InputABCD!) { /// control { /// test(new: $stream) { @@ -35,8 +33,8 @@ namespace graphql::client { /// } /// } /// } -/// -namespace nestedinput { +/// ``` +namespace client { // Return the original text of the request document. [[nodiscard("unnecessary call")]] const std::string& GetRequestText() noexcept; @@ -44,6 +42,8 @@ namespace nestedinput { // Return a pre-parsed, pre-validated request object. [[nodiscard("unnecessary call")]] const peg::ast& GetRequestObject() noexcept; +} // namespace client + struct [[nodiscard("unnecessary construction")]] InputA { explicit InputA() noexcept; @@ -116,20 +116,20 @@ struct [[nodiscard("unnecessary construction")]] InputBC InputB b; }; -} // namespace nestedinput +namespace client { namespace query::testQuery { -using nestedinput::GetRequestText; -using nestedinput::GetRequestObject; +using graphql::nestedinput::client::GetRequestText; +using graphql::nestedinput::client::GetRequestObject; // Return the name of this operation in the shared request document. [[nodiscard("unnecessary call")]] const std::string& GetOperationName() noexcept; -using nestedinput::InputA; -using nestedinput::InputB; -using nestedinput::InputABCD; -using nestedinput::InputBC; +using graphql::nestedinput::InputA; +using graphql::nestedinput::InputB; +using graphql::nestedinput::InputABCD; +using graphql::nestedinput::InputBC; struct [[nodiscard("unnecessary construction")]] Variables { @@ -171,6 +171,7 @@ struct Traits }; } // namespace query::testQuery -} // namespace graphql::client +} // namespace client +} // namespace graphql::nestedinput #endif // NESTEDINPUTCLIENT_H diff --git a/samples/client/nestedinput/NestedInputClient.ixx b/samples/client/nestedinput/NestedInputClient.ixx index c7f1253b..71430abe 100644 --- a/samples/client/nestedinput/NestedInputClient.ixx +++ b/samples/client/nestedinput/NestedInputClient.ixx @@ -9,30 +9,32 @@ module; export module GraphQL.NestedInput.NestedInputClient; -export namespace graphql::client { +export namespace graphql::nestedinput { -namespace nestedinput { +namespace client { -using nestedinput::GetRequestText; -using nestedinput::GetRequestObject; +using client::GetRequestText; +using client::GetRequestObject; + +} // namespace client using nestedinput::InputA; using nestedinput::InputB; using nestedinput::InputABCD; using nestedinput::InputBC; -} // namespace nestedinput +namespace client { namespace query::testQuery { -using nestedinput::GetRequestText; -using nestedinput::GetRequestObject; +using graphql::nestedinput::client::GetRequestText; +using graphql::nestedinput::client::GetRequestObject; using testQuery::GetOperationName; -using nestedinput::InputA; -using nestedinput::InputB; -using nestedinput::InputABCD; -using nestedinput::InputBC; +using graphql::nestedinput::InputA; +using graphql::nestedinput::InputB; +using graphql::nestedinput::InputABCD; +using graphql::nestedinput::InputBC; using testQuery::Variables; using testQuery::serializeVariables; @@ -44,4 +46,5 @@ using testQuery::Traits; } // namespace query::testQuery -} // namespace graphql::client +} // namespace client +} // namespace graphql::nestedinput diff --git a/samples/client/query/QueryClient.cpp b/samples/client/query/QueryClient.cpp index 0e874d20..46f381f0 100644 --- a/samples/client/query/QueryClient.cpp +++ b/samples/client/query/QueryClient.cpp @@ -16,8 +16,9 @@ using namespace std::literals; -namespace graphql::client { +namespace graphql { namespace query { +namespace client { const std::string& GetRequestText() noexcept { @@ -102,8 +103,11 @@ const peg::ast& GetRequestObject() noexcept return s_request; } +} // namespace client } // namespace query +namespace client { + using namespace query; template <> @@ -134,9 +138,9 @@ TaskState Response::parse(response::Value&& value) } template <> -query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment Response::parse(response::Value&& response) +graphql::query::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment Response::parse(response::Value&& response) { - query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment result; + graphql::query::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment result; if (response.type() == response::Type::Map) { @@ -176,9 +180,9 @@ query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdg } template <> -query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge Response::parse(response::Value&& response) +graphql::query::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge Response::parse(response::Value&& response) { - query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge result; + graphql::query::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge result; if (response.type() == response::Type::Map) { @@ -188,7 +192,7 @@ query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdg { if (member.first == R"js(node)js"sv) { - result.node = ModifiedResponse::parse(std::move(member.second)); + result.node = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -198,9 +202,9 @@ query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdg } template <> -query::Query::Response::appointments_AppointmentConnection Response::parse(response::Value&& response) +graphql::query::client::query::Query::Response::appointments_AppointmentConnection Response::parse(response::Value&& response) { - query::Query::Response::appointments_AppointmentConnection result; + graphql::query::client::query::Query::Response::appointments_AppointmentConnection result; if (response.type() == response::Type::Map) { @@ -210,7 +214,7 @@ query::Query::Response::appointments_AppointmentConnection Response::parse(std::move(member.second)); + result.edges = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -220,9 +224,9 @@ query::Query::Response::appointments_AppointmentConnection Response -query::Query::Response::tasks_TaskConnection::edges_TaskEdge::node_Task Response::parse(response::Value&& response) +graphql::query::client::query::Query::Response::tasks_TaskConnection::edges_TaskEdge::node_Task Response::parse(response::Value&& response) { - query::Query::Response::tasks_TaskConnection::edges_TaskEdge::node_Task result; + graphql::query::client::query::Query::Response::tasks_TaskConnection::edges_TaskEdge::node_Task result; if (response.type() == response::Type::Map) { @@ -257,9 +261,9 @@ query::Query::Response::tasks_TaskConnection::edges_TaskEdge::node_Task Response } template <> -query::Query::Response::tasks_TaskConnection::edges_TaskEdge Response::parse(response::Value&& response) +graphql::query::client::query::Query::Response::tasks_TaskConnection::edges_TaskEdge Response::parse(response::Value&& response) { - query::Query::Response::tasks_TaskConnection::edges_TaskEdge result; + graphql::query::client::query::Query::Response::tasks_TaskConnection::edges_TaskEdge result; if (response.type() == response::Type::Map) { @@ -269,7 +273,7 @@ query::Query::Response::tasks_TaskConnection::edges_TaskEdge Response::parse(std::move(member.second)); + result.node = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -279,9 +283,9 @@ query::Query::Response::tasks_TaskConnection::edges_TaskEdge Response -query::Query::Response::tasks_TaskConnection Response::parse(response::Value&& response) +graphql::query::client::query::Query::Response::tasks_TaskConnection Response::parse(response::Value&& response) { - query::Query::Response::tasks_TaskConnection result; + graphql::query::client::query::Query::Response::tasks_TaskConnection result; if (response.type() == response::Type::Map) { @@ -291,7 +295,7 @@ query::Query::Response::tasks_TaskConnection Response::parse(std::move(member.second)); + result.edges = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -301,9 +305,9 @@ query::Query::Response::tasks_TaskConnection Response -query::Query::Response::unreadCounts_FolderConnection::edges_FolderEdge::node_Folder Response::parse(response::Value&& response) +graphql::query::client::query::Query::Response::unreadCounts_FolderConnection::edges_FolderEdge::node_Folder Response::parse(response::Value&& response) { - query::Query::Response::unreadCounts_FolderConnection::edges_FolderEdge::node_Folder result; + graphql::query::client::query::Query::Response::unreadCounts_FolderConnection::edges_FolderEdge::node_Folder result; if (response.type() == response::Type::Map) { @@ -338,9 +342,9 @@ query::Query::Response::unreadCounts_FolderConnection::edges_FolderEdge::node_Fo } template <> -query::Query::Response::unreadCounts_FolderConnection::edges_FolderEdge Response::parse(response::Value&& response) +graphql::query::client::query::Query::Response::unreadCounts_FolderConnection::edges_FolderEdge Response::parse(response::Value&& response) { - query::Query::Response::unreadCounts_FolderConnection::edges_FolderEdge result; + graphql::query::client::query::Query::Response::unreadCounts_FolderConnection::edges_FolderEdge result; if (response.type() == response::Type::Map) { @@ -350,7 +354,7 @@ query::Query::Response::unreadCounts_FolderConnection::edges_FolderEdge Response { if (member.first == R"js(node)js"sv) { - result.node = ModifiedResponse::parse(std::move(member.second)); + result.node = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -360,9 +364,9 @@ query::Query::Response::unreadCounts_FolderConnection::edges_FolderEdge Response } template <> -query::Query::Response::unreadCounts_FolderConnection Response::parse(response::Value&& response) +graphql::query::client::query::Query::Response::unreadCounts_FolderConnection Response::parse(response::Value&& response) { - query::Query::Response::unreadCounts_FolderConnection result; + graphql::query::client::query::Query::Response::unreadCounts_FolderConnection result; if (response.type() == response::Type::Map) { @@ -372,7 +376,7 @@ query::Query::Response::unreadCounts_FolderConnection Response::parse(std::move(member.second)); + result.edges = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -382,9 +386,9 @@ query::Query::Response::unreadCounts_FolderConnection Response -query::Query::Response::anyType_UnionType Response::parse(response::Value&& response) +graphql::query::client::query::Query::Response::anyType_UnionType Response::parse(response::Value&& response) { - query::Query::Response::anyType_UnionType result; + graphql::query::client::query::Query::Response::anyType_UnionType result; if (response.type() == response::Type::Map) { @@ -433,7 +437,9 @@ query::Query::Response::anyType_UnionType Response -/// Operation: query (unnamed) -/// -/// +/// # Operation: query (unnamed) +/// ```graphql /// # Copyright (c) Microsoft Corporation. All rights reserved. /// # Licensed under the MIT License. /// @@ -89,8 +87,8 @@ namespace graphql::client { /// # Try a field with a C++ keyword /// default /// } -/// -namespace query { +/// ``` +namespace client { // Return the original text of the request document. [[nodiscard("unnecessary call")]] const std::string& GetRequestText() noexcept; @@ -98,6 +96,8 @@ namespace query { // Return a pre-parsed, pre-validated request object. [[nodiscard("unnecessary call")]] const peg::ast& GetRequestObject() noexcept; +} // namespace client + enum class [[nodiscard("unnecessary conversion")]] TaskState { Unassigned, @@ -106,17 +106,17 @@ enum class [[nodiscard("unnecessary conversion")]] TaskState Complete, }; -} // namespace query +namespace client { namespace query::Query { -using query::GetRequestText; -using query::GetRequestObject; +using graphql::query::client::GetRequestText; +using graphql::query::client::GetRequestObject; // Return the name of this operation in the shared request document. [[nodiscard("unnecessary call")]] const std::string& GetOperationName() noexcept; -using query::TaskState; +using graphql::query::TaskState; struct [[nodiscard("unnecessary construction")]] Response { @@ -208,6 +208,7 @@ struct Traits }; } // namespace query::Query -} // namespace graphql::client +} // namespace client +} // namespace graphql::query #endif // QUERYCLIENT_H diff --git a/samples/client/query/QueryClient.ixx b/samples/client/query/QueryClient.ixx index 97f91145..7d59ccdf 100644 --- a/samples/client/query/QueryClient.ixx +++ b/samples/client/query/QueryClient.ixx @@ -9,24 +9,26 @@ module; export module GraphQL.Query.QueryClient; -export namespace graphql::client { +export namespace graphql::query { -namespace query { +namespace client { -using query::GetRequestText; -using query::GetRequestObject; +using client::GetRequestText; +using client::GetRequestObject; + +} // namespace client using query::TaskState; -} // namespace query +namespace client { namespace query::Query { -using query::GetRequestText; -using query::GetRequestObject; +using graphql::query::client::GetRequestText; +using graphql::query::client::GetRequestObject; using Query::GetOperationName; -using query::TaskState; +using graphql::query::TaskState; using Query::Response; using Query::parseResponse; @@ -35,4 +37,5 @@ using Query::Traits; } // namespace query::Query -} // namespace graphql::client +} // namespace client +} // namespace graphql::query diff --git a/samples/client/subscribe/SubscribeClient.cpp b/samples/client/subscribe/SubscribeClient.cpp index ea516d6c..3945722a 100644 --- a/samples/client/subscribe/SubscribeClient.cpp +++ b/samples/client/subscribe/SubscribeClient.cpp @@ -16,8 +16,9 @@ using namespace std::literals; -namespace graphql::client { +namespace graphql { namespace subscribe { +namespace client { const std::string& GetRequestText() noexcept { @@ -52,14 +53,16 @@ const peg::ast& GetRequestObject() noexcept return s_request; } +} // namespace client } // namespace subscribe +namespace client { using namespace subscribe; template <> -subscription::TestSubscription::Response::nextAppointment_Appointment Response::parse(response::Value&& response) +graphql::subscribe::client::subscription::TestSubscription::Response::nextAppointment_Appointment Response::parse(response::Value&& response) { - subscription::TestSubscription::Response::nextAppointment_Appointment result; + graphql::subscribe::client::subscription::TestSubscription::Response::nextAppointment_Appointment result; if (response.type() == response::Type::Map) { @@ -93,7 +96,9 @@ subscription::TestSubscription::Response::nextAppointment_Appointment Response -/// Operation: subscription TestSubscription -/// -/// +/// # Operation: subscription TestSubscription +/// ```graphql /// # Copyright (c) Microsoft Corporation. All rights reserved. /// # Licensed under the MIT License. /// @@ -39,8 +37,8 @@ namespace graphql::client { /// isNow /// } /// } -/// -namespace subscribe { +/// ``` +namespace client { // Return the original text of the request document. [[nodiscard("unnecessary call")]] const std::string& GetRequestText() noexcept; @@ -48,12 +46,10 @@ namespace subscribe { // Return a pre-parsed, pre-validated request object. [[nodiscard("unnecessary call")]] const peg::ast& GetRequestObject() noexcept; -} // namespace subscribe - namespace subscription::TestSubscription { -using subscribe::GetRequestText; -using subscribe::GetRequestObject; +using graphql::subscribe::client::GetRequestText; +using graphql::subscribe::client::GetRequestObject; // Return the name of this operation in the shared request document. [[nodiscard("unnecessary call")]] const std::string& GetOperationName() noexcept; @@ -85,6 +81,7 @@ struct Traits }; } // namespace subscription::TestSubscription -} // namespace graphql::client +} // namespace client +} // namespace graphql::subscribe #endif // SUBSCRIBECLIENT_H diff --git a/samples/client/subscribe/SubscribeClient.ixx b/samples/client/subscribe/SubscribeClient.ixx index cf92a734..13456256 100644 --- a/samples/client/subscribe/SubscribeClient.ixx +++ b/samples/client/subscribe/SubscribeClient.ixx @@ -9,19 +9,17 @@ module; export module GraphQL.Subscribe.SubscribeClient; -export namespace graphql::client { +export namespace graphql::subscribe { -namespace subscribe { +namespace client { -using subscribe::GetRequestText; -using subscribe::GetRequestObject; - -} // namespace subscribe +using client::GetRequestText; +using client::GetRequestObject; namespace subscription::TestSubscription { -using subscribe::GetRequestText; -using subscribe::GetRequestObject; +using graphql::subscribe::client::GetRequestText; +using graphql::subscribe::client::GetRequestObject; using TestSubscription::GetOperationName; using TestSubscription::Response; @@ -31,4 +29,5 @@ using TestSubscription::Traits; } // namespace subscription::TestSubscription -} // namespace graphql::client +} // namespace client +} // namespace graphql::subscribe diff --git a/samples/proxy/client.cpp b/samples/proxy/client.cpp index 61893e72..2fbddc43 100644 --- a/samples/proxy/client.cpp +++ b/samples/proxy/client.cpp @@ -276,7 +276,7 @@ int main(int argc, char** argv) std::cout << "Executing query..." << std::endl; - using namespace client::query::relayQuery; + using namespace proxy::client::query::relayQuery; auto query = GetRequestObject(); auto variables = serializeVariables( @@ -286,7 +286,8 @@ int main(int argc, char** argv) auto serviceResponse = client::parseServiceResponse( service->resolve({ query, GetOperationName(), std::move(variables), launch, state }) .get()); - auto result = client::query::relayQuery::parseResponse(std::move(serviceResponse.data)); + auto result = + proxy::client::query::relayQuery::parseResponse(std::move(serviceResponse.data)); auto errors = std::move(serviceResponse.errors); if (result.relay.data) diff --git a/samples/proxy/query/ProxyClient.cpp b/samples/proxy/query/ProxyClient.cpp index 30ae06e1..6a9aecc8 100644 --- a/samples/proxy/query/ProxyClient.cpp +++ b/samples/proxy/query/ProxyClient.cpp @@ -16,8 +16,9 @@ using namespace std::literals; -namespace graphql::client { +namespace graphql { namespace proxy { +namespace client { const std::string& GetRequestText() noexcept { @@ -50,14 +51,16 @@ const peg::ast& GetRequestObject() noexcept return s_request; } +} // namespace client } // namespace proxy +namespace client { using namespace proxy; template <> -query::relayQuery::Response::relay_Results Response::parse(response::Value&& response) +graphql::proxy::client::query::relayQuery::Response::relay_Results Response::parse(response::Value&& response) { - query::relayQuery::Response::relay_Results result; + graphql::proxy::client::query::relayQuery::Response::relay_Results result; if (response.type() == response::Type::Map) { @@ -81,7 +84,9 @@ query::relayQuery::Response::relay_Results Response::serialize(std::move(variables.query))); @@ -103,6 +110,8 @@ response::Value serializeVariables(Variables&& variables) Response parseResponse(response::Value&& response) { + using namespace graphql::client; + Response result; if (response.type() == response::Type::Map) @@ -124,12 +133,12 @@ Response parseResponse(response::Value&& response) [[nodiscard("unnecessary call")]] const std::string& Traits::GetRequestText() noexcept { - return proxy::GetRequestText(); + return client::GetRequestText(); } [[nodiscard("unnecessary call")]] const peg::ast& Traits::GetRequestObject() noexcept { - return proxy::GetRequestObject(); + return client::GetRequestObject(); } [[nodiscard("unnecessary call")]] const std::string& Traits::GetOperationName() noexcept @@ -147,5 +156,5 @@ Response parseResponse(response::Value&& response) return relayQuery::parseResponse(std::move(response)); } -} // namespace query::relayQuery -} // namespace graphql::client +} // namespace proxy::client::query::relayQuery +} // namespace graphql diff --git a/samples/proxy/query/ProxyClient.h b/samples/proxy/query/ProxyClient.h index a2878c2f..90e75ad0 100644 --- a/samples/proxy/query/ProxyClient.h +++ b/samples/proxy/query/ProxyClient.h @@ -22,12 +22,10 @@ static_assert(graphql::internal::MajorVersion == 5, "regenerate with clientgen: major version mismatch"); static_assert(graphql::internal::MinorVersion == 0, "regenerate with clientgen: minor version mismatch"); -namespace graphql::client { +namespace graphql::proxy { -/// -/// Operation: query relayQuery -/// -/// +/// # Operation: query relayQuery +/// ```graphql /// # Copyright (c) Microsoft Corporation. All rights reserved. /// # Licensed under the MIT License. /// @@ -37,8 +35,8 @@ namespace graphql::client { /// errors /// } /// } -/// -namespace proxy { +/// ``` +namespace client { // Return the original text of the request document. [[nodiscard("unnecessary call")]] const std::string& GetRequestText() noexcept; @@ -46,12 +44,10 @@ namespace proxy { // Return a pre-parsed, pre-validated request object. [[nodiscard("unnecessary call")]] const peg::ast& GetRequestObject() noexcept; -} // namespace proxy - namespace query::relayQuery { -using proxy::GetRequestText; -using proxy::GetRequestObject; +using graphql::proxy::client::GetRequestText; +using graphql::proxy::client::GetRequestObject; // Return the name of this operation in the shared request document. [[nodiscard("unnecessary call")]] const std::string& GetOperationName() noexcept; @@ -94,6 +90,7 @@ struct Traits }; } // namespace query::relayQuery -} // namespace graphql::client +} // namespace client +} // namespace graphql::proxy #endif // PROXYCLIENT_H diff --git a/samples/proxy/query/ProxyClient.ixx b/samples/proxy/query/ProxyClient.ixx index e74294c1..8151c844 100644 --- a/samples/proxy/query/ProxyClient.ixx +++ b/samples/proxy/query/ProxyClient.ixx @@ -9,19 +9,17 @@ module; export module GraphQL.Proxy.ProxyClient; -export namespace graphql::client { +export namespace graphql::proxy { -namespace proxy { +namespace client { -using proxy::GetRequestText; -using proxy::GetRequestObject; - -} // namespace proxy +using client::GetRequestText; +using client::GetRequestObject; namespace query::relayQuery { -using proxy::GetRequestText; -using proxy::GetRequestObject; +using graphql::proxy::client::GetRequestText; +using graphql::proxy::client::GetRequestObject; using relayQuery::GetOperationName; using relayQuery::Variables; @@ -34,4 +32,5 @@ using relayQuery::Traits; } // namespace query::relayQuery -} // namespace graphql::client +} // namespace client +} // namespace graphql::proxy diff --git a/src/ClientGenerator.cpp b/src/ClientGenerator.cpp index 8af33dff..f8be81e8 100644 --- a/src/ClientGenerator.cpp +++ b/src/ClientGenerator.cpp @@ -99,7 +99,7 @@ std::string Generator::getSourcePath() const noexcept const std::string& Generator::getClientNamespace() const noexcept { - static const auto s_namespace = R"cpp(graphql::client)cpp"s; + static const auto s_namespace = R"cpp(client)cpp"s; return s_namespace; } @@ -209,12 +209,13 @@ static_assert(graphql::internal::MinorVersion == )cpp" )cpp"; - PendingBlankLine pendingSeparator { headerFile }; - NamespaceScope clientNamespaceScope { headerFile, getClientNamespace() }; + const auto schemaNamespace = std::format("graphql::{}", _schemaLoader.getSchemaNamespace()); + NamespaceScope schemaNamespaceScope { headerFile, schemaNamespace }; outputRequestComment(headerFile); - NamespaceScope schemaNamespaceScope { headerFile, _schemaLoader.getSchemaNamespace() }; + NamespaceScope clientNamespaceScope { headerFile, getClientNamespace() }; + PendingBlankLine pendingSeparator { headerFile }; outputGetRequestDeclaration(headerFile); @@ -235,6 +236,11 @@ static_assert(graphql::internal::MinorVersion == )cpp" pendingSeparator.reset(); + if (clientNamespaceScope.exit()) + { + headerFile << std::endl; + } + headerFile << R"cpp(enum class [[nodiscard("unnecessary conversion")]] )cpp" << cppType << R"cpp( { @@ -270,6 +276,11 @@ static_assert(graphql::internal::MinorVersion == )cpp" pendingSeparator.reset(); + if (clientNamespaceScope.exit()) + { + headerFile << std::endl; + } + if (!inputType.declarations.empty()) { // Forward declare nullable dependencies @@ -348,8 +359,10 @@ static_assert(graphql::internal::MinorVersion == )cpp" } pendingSeparator.reset(); - schemaNamespaceScope.exit(); - pendingSeparator.add(); + if (clientNamespaceScope.enter()) + { + pendingSeparator.add(); + } for (const auto& operation : operations) { @@ -358,9 +371,11 @@ static_assert(graphql::internal::MinorVersion == )cpp" NamespaceScope operationNamespaceScope { headerFile, getOperationNamespace(operation) }; headerFile << R"cpp( -using )cpp" << _schemaLoader.getSchemaNamespace() +using graphql::)cpp" + << _schemaLoader.getSchemaNamespace() << R"cpp(::)cpp" << getClientNamespace() << R"cpp(::GetRequestText; -using )cpp" << _schemaLoader.getSchemaNamespace() +using graphql::)cpp" + << _schemaLoader.getSchemaNamespace() << R"cpp(::)cpp" << getClientNamespace() << R"cpp(::GetRequestObject; )cpp"; @@ -369,8 +384,8 @@ using )cpp" << _schemaLoader.getSchemaNamespace() // Alias all of the enums referenced either in variables or the response. for (const auto& enumType : _requestLoader.getReferencedEnums(operation)) { - headerFile << R"cpp(using )cpp" << _schemaLoader.getSchemaNamespace() << R"cpp(::)cpp" - << _schemaLoader.getCppType(enumType->name()) << R"cpp(; + headerFile << R"cpp(using graphql::)cpp" << _schemaLoader.getSchemaNamespace() + << R"cpp(::)cpp" << _schemaLoader.getCppType(enumType->name()) << R"cpp(; )cpp"; pendingSeparator.add(); @@ -381,8 +396,9 @@ using )cpp" << _schemaLoader.getSchemaNamespace() // Alias all of the input object structs referenced in variables. for (const auto& inputType : _requestLoader.getReferencedInputTypes(operation)) { - headerFile << R"cpp(using )cpp" << _schemaLoader.getSchemaNamespace() << R"cpp(::)cpp" - << _schemaLoader.getCppType(inputType.type->name()) << R"cpp(; + headerFile << R"cpp(using graphql::)cpp" << _schemaLoader.getSchemaNamespace() + << R"cpp(::)cpp" << _schemaLoader.getCppType(inputType.type->name()) + << R"cpp(; )cpp"; pendingSeparator.add(); @@ -484,8 +500,7 @@ struct Traits void Generator::outputRequestComment(std::ostream& headerFile) const noexcept { headerFile << R"cpp( -/// -/// Operation)cpp"; +/// # Operation)cpp"; const auto& operations = _requestLoader.getOperations(); @@ -512,8 +527,7 @@ void Generator::outputRequestComment(std::ostream& headerFile) const noexcept } headerFile << R"cpp( -/// -/// +/// ```graphql )cpp"; std::istringstream request { std::string { _requestLoader.getRequestText() } }; @@ -523,7 +537,7 @@ void Generator::outputRequestComment(std::ostream& headerFile) const noexcept headerFile << R"cpp(/// )cpp" << line << std::endl; } - headerFile << R"cpp(/// + headerFile << R"cpp(/// ``` )cpp"; } @@ -640,17 +654,18 @@ export module GraphQL.)cpp" export )cpp"; - NamespaceScope graphqlNamespace { moduleFile, getClientNamespace() }; + const auto schemaNamespace = std::format("graphql::{}", _schemaLoader.getSchemaNamespace()); + NamespaceScope schemaNamespaceScope { moduleFile, schemaNamespace }; moduleFile << std::endl; - NamespaceScope schemaNamespace { moduleFile, _schemaLoader.getSchemaNamespace() }; + NamespaceScope clientNamespaceScope { moduleFile, getClientNamespace() }; PendingBlankLine pendingSeparator { moduleFile }; moduleFile << R"cpp( -using )cpp" << _schemaLoader.getSchemaNamespace() +using )cpp" << getClientNamespace() << R"cpp(::GetRequestText; -using )cpp" << _schemaLoader.getSchemaNamespace() +using )cpp" << getClientNamespace() << R"cpp(::GetRequestObject; )cpp"; @@ -663,6 +678,11 @@ using )cpp" << _schemaLoader.getSchemaNamespace() { pendingSeparator.reset(); + if (clientNamespaceScope.exit()) + { + moduleFile << std::endl; + } + // Define all of the enums referenced either in variables or the response. for (const auto& enumType : _requestLoader.getReferencedEnums(operation)) { @@ -694,6 +714,11 @@ using )cpp" << _schemaLoader.getSchemaNamespace() { pendingSeparator.reset(); + if (clientNamespaceScope.exit()) + { + moduleFile << std::endl; + } + // Define all of the input object structs referenced in variables. for (const auto& inputType : _requestLoader.getReferencedInputTypes(operation)) { @@ -717,7 +742,7 @@ using )cpp" << _schemaLoader.getSchemaNamespace() } pendingSeparator.reset(); - if (schemaNamespace.exit()) + if (clientNamespaceScope.enter()) { pendingSeparator.add(); } @@ -730,9 +755,11 @@ using )cpp" << _schemaLoader.getSchemaNamespace() const auto operationNamespace = _requestLoader.getOperationNamespace(operation); moduleFile << R"cpp( -using )cpp" << _schemaLoader.getSchemaNamespace() +using graphql::)cpp" + << _schemaLoader.getSchemaNamespace() << R"cpp(::)cpp" << getClientNamespace() << R"cpp(::GetRequestText; -using )cpp" << _schemaLoader.getSchemaNamespace() +using graphql::)cpp" + << _schemaLoader.getSchemaNamespace() << R"cpp(::)cpp" << getClientNamespace() << R"cpp(::GetRequestObject; using )cpp" << operationNamespace << R"cpp(::GetOperationName; @@ -742,8 +769,8 @@ using )cpp" << operationNamespace // Alias all of the enums referenced either in variables or the response. for (const auto& enumType : _requestLoader.getReferencedEnums(operation)) { - moduleFile << R"cpp(using )cpp" << _schemaLoader.getSchemaNamespace() << R"cpp(::)cpp" - << _schemaLoader.getCppType(enumType->name()) << R"cpp(; + moduleFile << R"cpp(using graphql::)cpp" << _schemaLoader.getSchemaNamespace() + << R"cpp(::)cpp" << _schemaLoader.getCppType(enumType->name()) << R"cpp(; )cpp"; pendingSeparator.add(); @@ -754,8 +781,9 @@ using )cpp" << operationNamespace // Alias all of the input object structs referenced in variables. for (const auto& inputType : _requestLoader.getReferencedInputTypes(operation)) { - moduleFile << R"cpp(using )cpp" << _schemaLoader.getSchemaNamespace() << R"cpp(::)cpp" - << _schemaLoader.getCppType(inputType.type->name()) << R"cpp(; + moduleFile << R"cpp(using graphql::)cpp" << _schemaLoader.getSchemaNamespace() + << R"cpp(::)cpp" << _schemaLoader.getCppType(inputType.type->name()) + << R"cpp(; )cpp"; pendingSeparator.add(); @@ -819,8 +847,9 @@ using namespace std::literals; )cpp"; - NamespaceScope clientNamespaceScope { sourceFile, getClientNamespace() }; + NamespaceScope graphqlNamespaceScope { sourceFile, "graphql" }; NamespaceScope schemaNamespaceScope { sourceFile, _schemaLoader.getSchemaNamespace() }; + NamespaceScope clientNamespaceScope { sourceFile, getClientNamespace() }; PendingBlankLine pendingSeparator { sourceFile }; outputGetRequestImplementation(sourceFile); @@ -841,6 +870,15 @@ using namespace std::literals; pendingSeparator.reset(); + if (clientNamespaceScope.exit()) + { + sourceFile << R"cpp( +using namespace graphql::)cpp" + << getClientNamespace() << R"cpp(; + +)cpp"; + } + sourceFile << cppType << R"cpp(::)cpp" << cppType << R"cpp(() noexcept)cpp"; bool firstField = true; @@ -979,14 +1017,11 @@ using namespace std::literals; } pendingSeparator.reset(); - schemaNamespaceScope.exit(); - - sourceFile << R"cpp( -using namespace )cpp" - << _schemaLoader.getSchemaNamespace() << R"cpp(; -)cpp"; - - pendingSeparator.add(); + clientNamespaceScope.exit(); + if (schemaNamespaceScope.exit()) + { + pendingSeparator.add(); + } std::unordered_set outputModifiedVariableEnum; std::unordered_set outputModifiedVariableInput; @@ -1009,6 +1044,15 @@ using namespace )cpp" pendingSeparator.reset(); + if (clientNamespaceScope.enter()) + { + sourceFile << R"cpp( +using namespace )cpp" << _schemaLoader.getSchemaNamespace() + << R"cpp(; + +)cpp"; + } + const auto& enumValues = enumType->enumValues(); sourceFile << R"cpp(template <> @@ -1058,10 +1102,18 @@ response::Value Variable<)cpp" pendingSeparator.reset(); + if (clientNamespaceScope.enter()) + { + sourceFile << R"cpp( +using namespace )cpp" << _schemaLoader.getSchemaNamespace() + << R"cpp(; + +)cpp"; + } + sourceFile << R"cpp(template <> response::Value Variable<)cpp" - << cppType << R"cpp(>::serialize()cpp" << cppType - << R"cpp(&& inputValue) + << cppType << R"cpp(>::serialize()cpp" << cppType << R"cpp(&& inputValue) { response::Value result { response::Type::Map }; @@ -1101,6 +1153,15 @@ response::Value Variable<)cpp" pendingSeparator.reset(); + if (clientNamespaceScope.enter()) + { + sourceFile << R"cpp( +using namespace )cpp" << _schemaLoader.getSchemaNamespace() + << R"cpp(; + +)cpp"; + } + const auto& enumValues = enumType->enumValues(); sourceFile << R"cpp(template <> @@ -1167,21 +1228,40 @@ response::Value Variable<)cpp" pendingSeparator.add(); } - const auto currentScope = - std::format(R"cpp({}::Response)cpp", getOperationNamespace(operation)); + const auto operationNamespace = std::format("{}::client::{}", + _schemaLoader.getSchemaNamespace(), + getOperationNamespace(operation)); + const auto graphqlCurrentScope = + std::format(R"cpp(graphql::{}::Response)cpp", operationNamespace); const auto& responseType = _requestLoader.getResponseType(operation); for (const auto& responseField : responseType.fields) { - if (outputModifiedResponseImplementation(sourceFile, currentScope, responseField)) + if (clientNamespaceScope.enter()) + { + sourceFile << R"cpp( +using namespace )cpp" << _schemaLoader.getSchemaNamespace() + << R"cpp(; +)cpp"; + } + + if (outputModifiedResponseImplementation(sourceFile, + graphqlCurrentScope, + responseField)) { pendingSeparator.add(); } } pendingSeparator.reset(); + if (clientNamespaceScope.exit()) + { + sourceFile << std::endl; + } - NamespaceScope operationNamespaceScope { sourceFile, getOperationNamespace(operation) }; + NamespaceScope operationNamespaceScope { sourceFile, operationNamespace }; + const auto schemaCurrentScope = + std::format("{}::Response", getOperationNamespace(operation)); outputGetOperationNameImplementation(sourceFile, operation); @@ -1190,6 +1270,9 @@ response::Value Variable<)cpp" sourceFile << R"cpp( response::Value serializeVariables(Variables&& variables) { + using namespace graphql::)cpp" + << getClientNamespace() << R"cpp(; + response::Value result { response::Type::Map }; )cpp"; @@ -1213,6 +1296,9 @@ response::Value serializeVariables(Variables&& variables) sourceFile << R"cpp( Response parseResponse(response::Value&& response) { + using namespace graphql::)cpp" + << getClientNamespace() << R"cpp(; + Response result; if (response.type() == response::Type::Map) @@ -1234,7 +1320,7 @@ Response parseResponse(response::Value&& response) { result.)cpp" << responseField.cppName << R"cpp( = ModifiedResponse<)cpp" - << getResponseFieldCppType(responseField, currentScope) + << getResponseFieldCppType(responseField, schemaCurrentScope) << R"cpp(>::parse)cpp" << getTypeModifierList(responseField.modifiers) << R"cpp((std::move(member.second)); continue; @@ -1251,13 +1337,13 @@ Response parseResponse(response::Value&& response) [[nodiscard("unnecessary call")]] const std::string& Traits::GetRequestText() noexcept { - return )cpp" << _schemaLoader.getSchemaNamespace() + return )cpp" << getClientNamespace() << R"cpp(::GetRequestText(); } [[nodiscard("unnecessary call")]] const peg::ast& Traits::GetRequestObject() noexcept { - return )cpp" << _schemaLoader.getSchemaNamespace() + return )cpp" << getClientNamespace() << R"cpp(::GetRequestObject(); } diff --git a/test/ClientTests.cpp b/test/ClientTests.cpp index 5a576b66..031e4c47 100644 --- a/test/ClientTests.cpp +++ b/test/ClientTests.cpp @@ -40,7 +40,7 @@ class ClientCase : public ::testing::Test TEST_F(ClientCase, QueryEverything) { - using namespace client::query::Query; + using namespace query::client::query::Query; auto query = GetRequestObject(); @@ -114,7 +114,7 @@ TEST_F(ClientCase, QueryEverything) EXPECT_EQ(3, unreadCountNode->unreadCount) << "unreadCount should match"; EXPECT_EQ("Folder", unreadCountNode->_typename) << "__typename should match"; - EXPECT_EQ(client::query::Query::TaskState::Unassigned, response.testTaskState) + EXPECT_EQ(query::client::query::Query::TaskState::Unassigned, response.testTaskState) << "testTaskState should match"; ASSERT_EQ(std::size_t { 1 }, response.anyType.size()) << "anyType should have 1 entry"; @@ -139,7 +139,7 @@ TEST_F(ClientCase, QueryEverything) TEST_F(ClientCase, MutateCompleteTask) { - using namespace client::mutation::CompleteTaskMutation; + using namespace mutate::client::mutation::CompleteTaskMutation; auto query = GetRequestObject(); auto variables = serializeVariables( @@ -181,7 +181,7 @@ TEST_F(ClientCase, MutateCompleteTask) TEST_F(ClientCase, SubscribeNextAppointmentChangeDefault) { - using namespace client::subscription::TestSubscription; + using namespace subscribe::client::subscription::TestSubscription; auto query = GetRequestObject(); From 88ec4632170949ad3d29d9b676034b7c4b651c5b Mon Sep 17 00:00:00 2001 From: Bill Avery Date: Thu, 19 Sep 2024 13:00:25 -0700 Subject: [PATCH 2/4] feat(sharetypes): reuse schema types in proxy client --- include/RequestLoader.h | 39 +- samples/proxy/client.cpp | 36 +- samples/proxy/query/CMakeLists.txt | 3 +- samples/proxy/query/ProxyClient.cpp | 70 +++- samples/proxy/query/ProxyClient.h | 18 +- samples/proxy/query/ProxyClient.ixx | 12 + samples/proxy/query/query.graphql | 4 +- samples/proxy/schema/ProxySchema.cpp | 160 +++++++- samples/proxy/schema/ProxySchema.h | 55 ++- samples/proxy/schema/ProxySchema.ixx | 10 +- samples/proxy/schema/QueryObject.cpp | 16 +- samples/proxy/schema/QueryObject.h | 16 +- ...sultsObject.cpp => QueryResultsObject.cpp} | 26 +- .../{ResultsObject.h => QueryResultsObject.h} | 32 +- ...sultsObject.ixx => QueryResultsObject.ixx} | 6 +- samples/proxy/schema/proxy_schema_files | 2 +- samples/proxy/schema/schema.graphql | 17 +- src/ClientGenerator.cpp | 367 ++++++++++-------- src/RequestLoader.cpp | 5 + 19 files changed, 608 insertions(+), 286 deletions(-) rename samples/proxy/schema/{ResultsObject.cpp => QueryResultsObject.cpp} (73%) rename samples/proxy/schema/{ResultsObject.h => QueryResultsObject.h} (80%) rename samples/proxy/schema/{ResultsObject.ixx => QueryResultsObject.ixx} (71%) diff --git a/include/RequestLoader.h b/include/RequestLoader.h index 8ec05d3c..96911e9b 100644 --- a/include/RequestLoader.h +++ b/include/RequestLoader.h @@ -84,6 +84,7 @@ struct [[nodiscard("unnecessary construction")]] RequestOptions const std::string requestFilename; const std::optional operationName; const bool noIntrospection = false; + const bool sharedTypes = false; }; class SchemaLoader; @@ -91,16 +92,16 @@ class SchemaLoader; class [[nodiscard("unnecessary construction")]] RequestLoader { public: - explicit RequestLoader(RequestOptions && requestOptions, const SchemaLoader& schemaLoader); + explicit RequestLoader(RequestOptions&& requestOptions, const SchemaLoader& schemaLoader); [[nodiscard("unnecessary call")]] std::string_view getRequestFilename() const noexcept; [[nodiscard("unnecessary call")]] const OperationList& getOperations() const noexcept; [[nodiscard("unnecessary call")]] std::string_view getOperationDisplayName( const Operation& operation) const noexcept; - [[nodiscard("unnecessary call")]] std::string getOperationNamespace(const Operation& operation) - const noexcept; - [[nodiscard("unnecessary call")]] std::string_view getOperationType(const Operation& operation) - const noexcept; + [[nodiscard("unnecessary call")]] std::string getOperationNamespace( + const Operation& operation) const noexcept; + [[nodiscard("unnecessary call")]] std::string_view getOperationType( + const Operation& operation) const noexcept; [[nodiscard("unnecessary call")]] std::string_view getRequestText() const noexcept; [[nodiscard("unnecessary call")]] const ResponseType& getResponseType( @@ -108,6 +109,7 @@ class [[nodiscard("unnecessary construction")]] RequestLoader [[nodiscard("unnecessary call")]] const RequestVariableList& getVariables( const Operation& operation) const noexcept; + [[nodiscard("unnecessary call")]] bool useSharedTypes() const noexcept; [[nodiscard("unnecessary call")]] const RequestInputTypeList& getReferencedInputTypes( const Operation& operation) const noexcept; [[nodiscard("unnecessary call")]] const RequestSchemaTypeList& getReferencedEnums( @@ -116,20 +118,18 @@ class [[nodiscard("unnecessary construction")]] RequestLoader [[nodiscard("unnecessary call")]] std::string getInputCppType( const RequestSchemaType& wrappedInputType) const noexcept; [[nodiscard("unnecessary call")]] std::string getInputCppType( - const RequestSchemaType& inputType, - const TypeModifierStack& modifiers) const noexcept; + const RequestSchemaType& inputType, const TypeModifierStack& modifiers) const noexcept; [[nodiscard("unnecessary call")]] static std::string getOutputCppType( - std::string_view outputCppType, - const TypeModifierStack& modifiers) noexcept; + std::string_view outputCppType, const TypeModifierStack& modifiers) noexcept; [[nodiscard("unnecessary call")]] static std::pair - unwrapSchemaType(RequestSchemaType && type) noexcept; + unwrapSchemaType(RequestSchemaType&& type) noexcept; private: void buildSchema(); void addTypesToSchema(); - [[nodiscard("unnecessary call")]] RequestSchemaType getSchemaType(std::string_view type, - const TypeModifierStack& modifiers) const noexcept; + [[nodiscard("unnecessary call")]] RequestSchemaType getSchemaType( + std::string_view type, const TypeModifierStack& modifiers) const noexcept; void validateRequest() const; [[nodiscard("unnecessary call")]] static std::string_view trimWhitespace( @@ -137,11 +137,11 @@ class [[nodiscard("unnecessary construction")]] RequestLoader void findOperation(); void collectFragments() noexcept; - void collectVariables(Operation & operation) noexcept; - void collectInputTypes(Operation & operation, const RequestSchemaType& variableType) noexcept; - void reorderInputTypeDependencies(Operation & operation); - void collectEnums(Operation & operation, const RequestSchemaType& variableType) noexcept; - void collectEnums(Operation & operation, const ResponseField& responseField) noexcept; + void collectVariables(Operation& operation) noexcept; + void collectInputTypes(Operation& operation, const RequestSchemaType& variableType) noexcept; + void reorderInputTypeDependencies(Operation& operation); + void collectEnums(Operation& operation, const RequestSchemaType& variableType) noexcept; + void collectEnums(Operation& operation, const ResponseField& responseField) noexcept; using FragmentDefinitionMap = std::map; @@ -150,8 +150,7 @@ class [[nodiscard("unnecessary construction")]] RequestLoader { public: explicit SelectionVisitor(const SchemaLoader& schemaLoader, - const FragmentDefinitionMap& fragments, - const std::shared_ptr& schema, + const FragmentDefinitionMap& fragments, const std::shared_ptr& schema, const RequestSchemaType& type); void visit(const peg::ast_node& selection); @@ -163,7 +162,7 @@ class [[nodiscard("unnecessary construction")]] RequestLoader void visitFragmentSpread(const peg::ast_node& fragmentSpread); void visitInlineFragment(const peg::ast_node& inlineFragment); - void mergeFragmentFields(ResponseFieldList && fragmentFields) noexcept; + void mergeFragmentFields(ResponseFieldList&& fragmentFields) noexcept; const SchemaLoader& _schemaLoader; const FragmentDefinitionMap& _fragments; diff --git a/samples/proxy/client.cpp b/samples/proxy/client.cpp index 2fbddc43..5b09b6f2 100644 --- a/samples/proxy/client.cpp +++ b/samples/proxy/client.cpp @@ -5,7 +5,7 @@ #include "schema/ProxySchema.h" #include "schema/QueryObject.h" -#include "schema/ResultsObject.h" +#include "schema/QueryResultsObject.h" #include "graphqlservice/JSONResponse.h" @@ -151,9 +151,8 @@ class Query explicit Query(std::string_view host, std::string_view port, std::string_view target, int version) noexcept; - std::future> getRelay(std::string&& queryArg, - std::optional&& operationNameArg, - std::optional&& variablesArg) const; + std::future> getRelay( + proxy::QueryInput&& inputArg) const; private: const std::string m_host; @@ -173,21 +172,22 @@ Query::Query( // Based on: // https://www.boost.org/doc/libs/1_82_0/libs/beast/example/http/client/awaitable/http_client_awaitable.cpp -std::future> Query::getRelay(std::string&& queryArg, - std::optional&& operationNameArg, std::optional&& variablesArg) const +std::future> Query::getRelay( + proxy::QueryInput&& inputArg) const { response::Value payload { response::Type::Map }; - payload.emplace_back("query"s, response::Value { std::move(queryArg) }); + payload.emplace_back("query"s, response::Value { std::move(inputArg.query) }); - if (operationNameArg) + if (inputArg.operationName) { - payload.emplace_back("operationName"s, response::Value { std::move(*operationNameArg) }); + payload.emplace_back("operationName"s, + response::Value { std::move(*inputArg.operationName) }); } - if (variablesArg) + if (inputArg.variables) { - payload.emplace_back("variables"s, response::Value { std::move(*variablesArg) }); + payload.emplace_back("variables"s, response::Value { std::move(*inputArg.variables) }); } std::string requestBody = response::toJSON(std::move(payload)); @@ -199,7 +199,8 @@ std::future> Query::getRelay(std::string const char* port, const char* target, int version, - std::string requestBody) -> net::awaitable> { + std::string requestBody) + -> net::awaitable> { // These objects perform our I/O. They use an executor with a default completion token // of use_awaitable. This makes our code easy, but will use exceptions as the default // error handling, i.e. if the connection drops, we might see an exception. @@ -252,7 +253,7 @@ std::future> Query::getRelay(std::string auto [data, errors] = client::parseServiceResponse(response::parseJSON(res.body())); - co_return std::make_shared( + co_return std::make_shared( std::make_shared(std::move(data), std::move(errors))); }(m_host.c_str(), m_port.c_str(), m_target.c_str(), m_version, std::move(requestBody)), net::use_future); @@ -279,15 +280,16 @@ int main(int argc, char** argv) using namespace proxy::client::query::relayQuery; auto query = GetRequestObject(); - auto variables = serializeVariables( - { input, ((argc > 1) ? std::make_optional(argv[1]) : std::nullopt) }); + auto variables = serializeVariables({ QueryInput { OperationType::QUERY, + input, + ((argc > 1) ? std::make_optional(argv[1]) : std::nullopt), + std::nullopt } }); auto launch = service::await_async { std::make_shared() }; auto state = std::make_shared(); auto serviceResponse = client::parseServiceResponse( service->resolve({ query, GetOperationName(), std::move(variables), launch, state }) .get()); - auto result = - proxy::client::query::relayQuery::parseResponse(std::move(serviceResponse.data)); + auto result = parseResponse(std::move(serviceResponse.data)); auto errors = std::move(serviceResponse.errors); if (result.relay.data) diff --git a/samples/proxy/query/CMakeLists.txt b/samples/proxy/query/CMakeLists.txt index 4c8e5e50..8c4fcdb0 100644 --- a/samples/proxy/query/CMakeLists.txt +++ b/samples/proxy/query/CMakeLists.txt @@ -7,7 +7,8 @@ cmake_minimum_required(VERSION 3.28) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/cppgraphqlgen-functions.cmake) if(GRAPHQL_UPDATE_SAMPLES AND GRAPHQL_BUILD_CLIENTGEN) - update_graphql_client_files(proxy ../schema/schema.graphql query.graphql Proxy proxy) + update_graphql_client_files(proxy ../schema/schema.graphql query.graphql Proxy proxy --shared-types) endif() add_graphql_client_target(proxy) +target_link_libraries(proxy_client PRIVATE proxy_schema) \ No newline at end of file diff --git a/samples/proxy/query/ProxyClient.cpp b/samples/proxy/query/ProxyClient.cpp index 6a9aecc8..d40a39a9 100644 --- a/samples/proxy/query/ProxyClient.cpp +++ b/samples/proxy/query/ProxyClient.cpp @@ -26,8 +26,8 @@ const std::string& GetRequestText() noexcept # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. - query relayQuery($query: String!, $operationName: String, $variables: String) { - relay(query: $query, operationName: $operationName, variables: $variables) { + query relayQuery($input: QueryInput!) { + relay(input: $input) { data errors } @@ -53,14 +53,70 @@ const peg::ast& GetRequestObject() noexcept } // namespace client } // namespace proxy + namespace client { using namespace proxy; template <> -graphql::proxy::client::query::relayQuery::Response::relay_Results Response::parse(response::Value&& response) +response::Value Variable::serialize(OperationType&& value) +{ + static const std::array s_names = { + R"gql(QUERY)gql"sv, + R"gql(MUTATION)gql"sv, + R"gql(SUBSCRIPTION)gql"sv + }; + + response::Value result { response::Type::EnumValue }; + + result.set(std::string { s_names[static_cast(value)] }); + + return result; +} + +template <> +response::Value Variable::serialize(QueryInput&& inputValue) +{ + response::Value result { response::Type::Map }; + + result.emplace_back(R"js(type)js"s, ModifiedVariable::serialize(std::move(inputValue.type))); + result.emplace_back(R"js(query)js"s, ModifiedVariable::serialize(std::move(inputValue.query))); + result.emplace_back(R"js(operationName)js"s, ModifiedVariable::serialize(std::move(inputValue.operationName))); + result.emplace_back(R"js(variables)js"s, ModifiedVariable::serialize(std::move(inputValue.variables))); + + return result; +} + +template <> +OperationType Response::parse(response::Value&& value) +{ + if (!value.maybe_enum()) + { + throw std::logic_error { R"ex(not a valid OperationType value)ex" }; + } + + static const std::array, 3> s_values = { + std::make_pair(R"gql(QUERY)gql"sv, OperationType::QUERY), + std::make_pair(R"gql(MUTATION)gql"sv, OperationType::MUTATION), + std::make_pair(R"gql(SUBSCRIPTION)gql"sv, OperationType::SUBSCRIPTION) + }; + + const auto result = internal::sorted_map_lookup( + s_values, + std::string_view { value.get() }); + + if (!result) + { + throw std::logic_error { R"ex(not a valid OperationType value)ex" }; + } + + return *result; +} + +template <> +graphql::proxy::client::query::relayQuery::Response::relay_QueryResults Response::parse(response::Value&& response) { - graphql::proxy::client::query::relayQuery::Response::relay_Results result; + graphql::proxy::client::query::relayQuery::Response::relay_QueryResults result; if (response.type() == response::Type::Map) { @@ -101,9 +157,7 @@ response::Value serializeVariables(Variables&& variables) response::Value result { response::Type::Map }; - result.emplace_back(R"js(query)js"s, ModifiedVariable::serialize(std::move(variables.query))); - result.emplace_back(R"js(operationName)js"s, ModifiedVariable::serialize(std::move(variables.operationName))); - result.emplace_back(R"js(variables)js"s, ModifiedVariable::serialize(std::move(variables.variables))); + result.emplace_back(R"js(input)js"s, ModifiedVariable::serialize(std::move(variables.input))); return result; } @@ -122,7 +176,7 @@ Response parseResponse(response::Value&& response) { if (member.first == R"js(relay)js"sv) { - result.relay = ModifiedResponse::parse(std::move(member.second)); + result.relay = ModifiedResponse::parse(std::move(member.second)); continue; } } diff --git a/samples/proxy/query/ProxyClient.h b/samples/proxy/query/ProxyClient.h index 90e75ad0..f541794f 100644 --- a/samples/proxy/query/ProxyClient.h +++ b/samples/proxy/query/ProxyClient.h @@ -14,6 +14,8 @@ #include "graphqlservice/internal/Version.h" +#include "ProxySchema.h" + #include #include #include @@ -29,8 +31,8 @@ namespace graphql::proxy { /// # Copyright (c) Microsoft Corporation. All rights reserved. /// # Licensed under the MIT License. /// -/// query relayQuery($query: String!, $operationName: String, $variables: String) { -/// relay(query: $query, operationName: $operationName, variables: $variables) { +/// query relayQuery($input: QueryInput!) { +/// relay(input: $input) { /// data /// errors /// } @@ -52,24 +54,26 @@ using graphql::proxy::client::GetRequestObject; // Return the name of this operation in the shared request document. [[nodiscard("unnecessary call")]] const std::string& GetOperationName() noexcept; +using graphql::proxy::OperationType; + +using graphql::proxy::QueryInput; + struct [[nodiscard("unnecessary construction")]] Variables { - std::string query {}; - std::optional operationName {}; - std::optional variables {}; + QueryInput input {}; }; [[nodiscard("unnecessary conversion")]] response::Value serializeVariables(Variables&& variables); struct [[nodiscard("unnecessary construction")]] Response { - struct [[nodiscard("unnecessary construction")]] relay_Results + struct [[nodiscard("unnecessary construction")]] relay_QueryResults { std::optional data {}; std::optional>> errors {}; }; - relay_Results relay {}; + relay_QueryResults relay {}; }; [[nodiscard("unnecessary conversion")]] Response parseResponse(response::Value&& response); diff --git a/samples/proxy/query/ProxyClient.ixx b/samples/proxy/query/ProxyClient.ixx index 8151c844..d83227a1 100644 --- a/samples/proxy/query/ProxyClient.ixx +++ b/samples/proxy/query/ProxyClient.ixx @@ -16,12 +16,24 @@ namespace client { using client::GetRequestText; using client::GetRequestObject; +} // namespace client + +using proxy::OperationType; + +using proxy::QueryInput; + +namespace client { + namespace query::relayQuery { using graphql::proxy::client::GetRequestText; using graphql::proxy::client::GetRequestObject; using relayQuery::GetOperationName; +using graphql::proxy::OperationType; + +using graphql::proxy::QueryInput; + using relayQuery::Variables; using relayQuery::serializeVariables; diff --git a/samples/proxy/query/query.graphql b/samples/proxy/query/query.graphql index 54ca8e60..63567f4b 100644 --- a/samples/proxy/query/query.graphql +++ b/samples/proxy/query/query.graphql @@ -1,8 +1,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -query relayQuery($query: String!, $operationName: String, $variables: String) { - relay(query: $query, operationName: $operationName, variables: $variables) { +query relayQuery($input: QueryInput!) { + relay(input: $input) { data errors } diff --git a/samples/proxy/schema/ProxySchema.cpp b/samples/proxy/schema/ProxySchema.cpp index a4ef637d..5f2c26b4 100644 --- a/samples/proxy/schema/ProxySchema.cpp +++ b/samples/proxy/schema/ProxySchema.cpp @@ -21,8 +21,145 @@ using namespace std::literals; namespace graphql { +namespace service { + +static const auto s_namesOperationType = proxy::getOperationTypeNames(); +static const auto s_valuesOperationType = proxy::getOperationTypeValues(); + +template <> +proxy::OperationType Argument::convert(const response::Value& value) +{ + if (!value.maybe_enum()) + { + throw service::schema_exception { { R"ex(not a valid OperationType value)ex" } }; + } + + const auto result = internal::sorted_map_lookup( + s_valuesOperationType, + std::string_view { value.get() }); + + if (!result) + { + throw service::schema_exception { { R"ex(not a valid OperationType value)ex" } }; + } + + return *result; +} + +template <> +service::AwaitableResolver Result::convert(service::AwaitableScalar result, ResolverParams&& params) +{ + return ModifiedResult::resolve(std::move(result), std::move(params), + [](proxy::OperationType value, const ResolverParams&) + { + response::Value resolvedResult(response::Type::EnumValue); + + resolvedResult.set(std::string { s_namesOperationType[static_cast(value)] }); + + return resolvedResult; + }); +} + +template <> +void Result::validateScalar(const response::Value& value) +{ + if (!value.maybe_enum()) + { + throw service::schema_exception { { R"ex(not a valid OperationType value)ex" } }; + } + + const auto [itr, itrEnd] = internal::sorted_map_equal_range( + s_valuesOperationType.begin(), + s_valuesOperationType.end(), + std::string_view { value.get() }); + + if (itr == itrEnd) + { + throw service::schema_exception { { R"ex(not a valid OperationType value)ex" } }; + } +} + +template <> +proxy::QueryInput Argument::convert(const response::Value& value) +{ + auto valueType = service::ModifiedArgument::require("type", value); + auto valueQuery = service::ModifiedArgument::require("query", value); + auto valueOperationName = service::ModifiedArgument::require("operationName", value); + auto valueVariables = service::ModifiedArgument::require("variables", value); + + return proxy::QueryInput { + std::move(valueType), + std::move(valueQuery), + std::move(valueOperationName), + std::move(valueVariables) + }; +} + +} // namespace service + namespace proxy { +QueryInput::QueryInput() noexcept + : type {} + , query {} + , operationName {} + , variables {} +{ + // Explicit definition to prevent ODR violations when LTO is enabled. +} + +QueryInput::QueryInput( + OperationType typeArg, + std::string queryArg, + std::optional operationNameArg, + std::optional variablesArg) noexcept + : type { std::move(typeArg) } + , query { std::move(queryArg) } + , operationName { std::move(operationNameArg) } + , variables { std::move(variablesArg) } +{ +} + +QueryInput::QueryInput(const QueryInput& other) + : type { service::ModifiedArgument::duplicate(other.type) } + , query { service::ModifiedArgument::duplicate(other.query) } + , operationName { service::ModifiedArgument::duplicate(other.operationName) } + , variables { service::ModifiedArgument::duplicate(other.variables) } +{ +} + +QueryInput::QueryInput(QueryInput&& other) noexcept + : type { std::move(other.type) } + , query { std::move(other.query) } + , operationName { std::move(other.operationName) } + , variables { std::move(other.variables) } +{ +} + +QueryInput::~QueryInput() +{ + // Explicit definition to prevent ODR violations when LTO is enabled. +} + +QueryInput& QueryInput::operator=(const QueryInput& other) +{ + QueryInput value { other }; + + std::swap(*this, value); + + return *this; +} + +QueryInput& QueryInput::operator=(QueryInput&& other) noexcept +{ + type = std::move(other.type); + query = std::move(other.query); + operationName = std::move(other.operationName); + variables = std::move(other.variables); + + return *this; +} + Operations::Operations(std::shared_ptr query) : service::Request({ { service::strQuery, query } @@ -33,13 +170,30 @@ Operations::Operations(std::shared_ptr query) void AddTypesToSchema(const std::shared_ptr& schema) { + auto typeOperationType = schema::EnumType::Make(R"gql(OperationType)gql"sv, R"md()md"sv); + schema->AddType(R"gql(OperationType)gql"sv, typeOperationType); + auto typeQueryInput = schema::InputObjectType::Make(R"gql(QueryInput)gql"sv, R"md()md"sv); + schema->AddType(R"gql(QueryInput)gql"sv, typeQueryInput); auto typeQuery = schema::ObjectType::Make(R"gql(Query)gql"sv, R"md()md"sv); schema->AddType(R"gql(Query)gql"sv, typeQuery); - auto typeResults = schema::ObjectType::Make(R"gql(Results)gql"sv, R"md()md"sv); - schema->AddType(R"gql(Results)gql"sv, typeResults); + auto typeQueryResults = schema::ObjectType::Make(R"gql(QueryResults)gql"sv, R"md()md"sv); + schema->AddType(R"gql(QueryResults)gql"sv, typeQueryResults); + + typeOperationType->AddEnumValues({ + { service::s_namesOperationType[static_cast(proxy::OperationType::QUERY)], R"md()md"sv, std::nullopt }, + { service::s_namesOperationType[static_cast(proxy::OperationType::MUTATION)], R"md()md"sv, std::nullopt }, + { service::s_namesOperationType[static_cast(proxy::OperationType::SUBSCRIPTION)], R"md()md"sv, std::nullopt } + }); + + typeQueryInput->AddInputValues({ + schema::InputValue::Make(R"gql(type)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(OperationType)gql"sv)), R"gql()gql"sv), + schema::InputValue::Make(R"gql(query)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(String)gql"sv)), R"gql()gql"sv), + schema::InputValue::Make(R"gql(operationName)gql"sv, R"md()md"sv, schema->LookupType(R"gql(String)gql"sv), R"gql(null)gql"sv), + schema::InputValue::Make(R"gql(variables)gql"sv, R"md()md"sv, schema->LookupType(R"gql(String)gql"sv), R"gql(null)gql"sv) + }); AddQueryDetails(typeQuery, schema); - AddResultsDetails(typeResults, schema); + AddQueryResultsDetails(typeQueryResults, schema); schema->AddQueryType(typeQuery); } diff --git a/samples/proxy/schema/ProxySchema.h b/samples/proxy/schema/ProxySchema.h index 9d4e544d..849cfb60 100644 --- a/samples/proxy/schema/ProxySchema.h +++ b/samples/proxy/schema/ProxySchema.h @@ -25,10 +25,61 @@ static_assert(graphql::internal::MinorVersion == 0, "regenerate with schemagen: namespace graphql { namespace proxy { + +enum class [[nodiscard("unnecessary conversion")]] OperationType +{ + QUERY, + MUTATION, + SUBSCRIPTION +}; + +[[nodiscard("unnecessary call")]] constexpr auto getOperationTypeNames() noexcept +{ + using namespace std::literals; + + return std::array { + R"gql(QUERY)gql"sv, + R"gql(MUTATION)gql"sv, + R"gql(SUBSCRIPTION)gql"sv + }; +} + +[[nodiscard("unnecessary call")]] constexpr auto getOperationTypeValues() noexcept +{ + using namespace std::literals; + + return std::array, 3> { + std::make_pair(R"gql(QUERY)gql"sv, OperationType::QUERY), + std::make_pair(R"gql(MUTATION)gql"sv, OperationType::MUTATION), + std::make_pair(R"gql(SUBSCRIPTION)gql"sv, OperationType::SUBSCRIPTION) + }; +} + +struct [[nodiscard("unnecessary construction")]] QueryInput +{ + explicit QueryInput() noexcept; + explicit QueryInput( + OperationType typeArg, + std::string queryArg, + std::optional operationNameArg, + std::optional variablesArg) noexcept; + QueryInput(const QueryInput& other); + QueryInput(QueryInput&& other) noexcept; + ~QueryInput(); + + QueryInput& operator=(const QueryInput& other); + QueryInput& operator=(QueryInput&& other) noexcept; + + OperationType type; + std::string query; + std::optional operationName; + std::optional variables; +}; + namespace object { class Query; -class Results; +class QueryResults; } // namespace object @@ -51,7 +102,7 @@ class [[nodiscard("unnecessary construction")]] Operations final }; void AddQueryDetails(const std::shared_ptr& typeQuery, const std::shared_ptr& schema); -void AddResultsDetails(const std::shared_ptr& typeResults, const std::shared_ptr& schema); +void AddQueryResultsDetails(const std::shared_ptr& typeQueryResults, const std::shared_ptr& schema); std::shared_ptr GetSchema(); diff --git a/samples/proxy/schema/ProxySchema.ixx b/samples/proxy/schema/ProxySchema.ixx index c0b1b5b2..0b646c10 100644 --- a/samples/proxy/schema/ProxySchema.ixx +++ b/samples/proxy/schema/ProxySchema.ixx @@ -10,14 +10,20 @@ module; export module GraphQL.Proxy.ProxySchema; export import GraphQL.Proxy.QueryObject; -export import GraphQL.Proxy.ResultsObject; +export import GraphQL.Proxy.QueryResultsObject; export namespace graphql::proxy { +using proxy::OperationType; +using proxy::getOperationTypeNames; +using proxy::getOperationTypeValues; + +using proxy::QueryInput; + using proxy::Operations; using proxy::AddQueryDetails; -using proxy::AddResultsDetails; +using proxy::AddQueryResultsDetails; using proxy::GetSchema; diff --git a/samples/proxy/schema/QueryObject.cpp b/samples/proxy/schema/QueryObject.cpp index d4dfb635..cdfc3817 100644 --- a/samples/proxy/schema/QueryObject.cpp +++ b/samples/proxy/schema/QueryObject.cpp @@ -4,7 +4,7 @@ // WARNING! Do not edit this file manually, your changes will be overwritten. #include "QueryObject.h" -#include "ResultsObject.h" +#include "QueryResultsObject.h" #include "graphqlservice/internal/Introspection.h" @@ -57,16 +57,14 @@ void Query::endSelectionSet(const service::SelectionSetParams& params) const service::AwaitableResolver Query::resolveRelay(service::ResolverParams&& params) const { - auto argQuery = service::ModifiedArgument::require("query", params.arguments); - auto argOperationName = service::ModifiedArgument::require("operationName", params.arguments); - auto argVariables = service::ModifiedArgument::require("variables", params.arguments); + auto argInput = service::ModifiedArgument::require("input", params.arguments); std::unique_lock resolverLock(_resolverMutex); service::SelectionSetParams selectionSetParams { static_cast(params) }; auto directives = std::move(params.fieldDirectives); - auto result = _pimpl->getRelay(service::FieldParams { std::move(selectionSetParams), std::move(directives) }, std::move(argQuery), std::move(argOperationName), std::move(argVariables)); + auto result = _pimpl->getRelay(service::FieldParams { std::move(selectionSetParams), std::move(directives) }, std::move(argInput)); resolverLock.unlock(); - return service::ModifiedResult::convert(std::move(result), std::move(params)); + return service::ModifiedResult::convert(std::move(result), std::move(params)); } service::AwaitableResolver Query::resolve_typename(service::ResolverParams&& params) const @@ -93,10 +91,8 @@ service::AwaitableResolver Query::resolve_type(service::ResolverParams&& params) void AddQueryDetails(const std::shared_ptr& typeQuery, const std::shared_ptr& schema) { typeQuery->AddFields({ - schema::Field::Make(R"gql(relay)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(Results)gql"sv)), { - schema::InputValue::Make(R"gql(query)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(String)gql"sv)), R"gql()gql"sv), - schema::InputValue::Make(R"gql(operationName)gql"sv, R"md()md"sv, schema->LookupType(R"gql(String)gql"sv), R"gql()gql"sv), - schema::InputValue::Make(R"gql(variables)gql"sv, R"md()md"sv, schema->LookupType(R"gql(String)gql"sv), R"gql()gql"sv) + schema::Field::Make(R"gql(relay)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(QueryResults)gql"sv)), { + schema::InputValue::Make(R"gql(input)gql"sv, R"md()md"sv, schema->WrapType(introspection::TypeKind::NON_NULL, schema->LookupType(R"gql(QueryInput)gql"sv)), R"gql()gql"sv) }) }); } diff --git a/samples/proxy/schema/QueryObject.h b/samples/proxy/schema/QueryObject.h index 0afd51de..ed350a05 100644 --- a/samples/proxy/schema/QueryObject.h +++ b/samples/proxy/schema/QueryObject.h @@ -14,15 +14,15 @@ namespace graphql::proxy::object { namespace methods::QueryHas { template -concept getRelayWithParams = requires (TImpl impl, service::FieldParams params, std::string queryArg, std::optional operationNameArg, std::optional variablesArg) +concept getRelayWithParams = requires (TImpl impl, service::FieldParams params, QueryInput inputArg) { - { service::AwaitableObject> { impl.getRelay(std::move(params), std::move(queryArg), std::move(operationNameArg), std::move(variablesArg)) } }; + { service::AwaitableObject> { impl.getRelay(std::move(params), std::move(inputArg)) } }; }; template -concept getRelay = requires (TImpl impl, std::string queryArg, std::optional operationNameArg, std::optional variablesArg) +concept getRelay = requires (TImpl impl, QueryInput inputArg) { - { service::AwaitableObject> { impl.getRelay(std::move(queryArg), std::move(operationNameArg), std::move(variablesArg)) } }; + { service::AwaitableObject> { impl.getRelay(std::move(inputArg)) } }; }; template @@ -58,7 +58,7 @@ class [[nodiscard("unnecessary construction")]] Query final virtual void beginSelectionSet(const service::SelectionSetParams& params) const = 0; virtual void endSelectionSet(const service::SelectionSetParams& params) const = 0; - [[nodiscard("unnecessary call")]] virtual service::AwaitableObject> getRelay(service::FieldParams&& params, std::string&& queryArg, std::optional&& operationNameArg, std::optional&& variablesArg) const = 0; + [[nodiscard("unnecessary call")]] virtual service::AwaitableObject> getRelay(service::FieldParams&& params, QueryInput&& inputArg) const = 0; }; template @@ -70,16 +70,16 @@ class [[nodiscard("unnecessary construction")]] Query final { } - [[nodiscard("unnecessary call")]] service::AwaitableObject> getRelay(service::FieldParams&& params, std::string&& queryArg, std::optional&& operationNameArg, std::optional&& variablesArg) const override + [[nodiscard("unnecessary call")]] service::AwaitableObject> getRelay(service::FieldParams&& params, QueryInput&& inputArg) const override { if constexpr (methods::QueryHas::getRelayWithParams) { - return { _pimpl->getRelay(std::move(params), std::move(queryArg), std::move(operationNameArg), std::move(variablesArg)) }; + return { _pimpl->getRelay(std::move(params), std::move(inputArg)) }; } else { static_assert(methods::QueryHas::getRelay, R"msg(Query::getRelay is not implemented)msg"); - return { _pimpl->getRelay(std::move(queryArg), std::move(operationNameArg), std::move(variablesArg)) }; + return { _pimpl->getRelay(std::move(inputArg)) }; } } diff --git a/samples/proxy/schema/ResultsObject.cpp b/samples/proxy/schema/QueryResultsObject.cpp similarity index 73% rename from samples/proxy/schema/ResultsObject.cpp rename to samples/proxy/schema/QueryResultsObject.cpp index 444f4b81..80d2e5f0 100644 --- a/samples/proxy/schema/ResultsObject.cpp +++ b/samples/proxy/schema/QueryResultsObject.cpp @@ -3,7 +3,7 @@ // WARNING! Do not edit this file manually, your changes will be overwritten. -#include "ResultsObject.h" +#include "QueryResultsObject.h" #include "graphqlservice/internal/Schema.h" @@ -19,20 +19,20 @@ using namespace std::literals; namespace graphql::proxy { namespace object { -Results::Results(std::unique_ptr pimpl) noexcept +QueryResults::QueryResults(std::unique_ptr pimpl) noexcept : service::Object{ getTypeNames(), getResolvers() } , _pimpl { std::move(pimpl) } { } -service::TypeNames Results::getTypeNames() const noexcept +service::TypeNames QueryResults::getTypeNames() const noexcept { return { - R"gql(Results)gql"sv + R"gql(QueryResults)gql"sv }; } -service::ResolverMap Results::getResolvers() const noexcept +service::ResolverMap QueryResults::getResolvers() const noexcept { return { { R"gql(data)gql"sv, [this](service::ResolverParams&& params) { return resolveData(std::move(params)); } }, @@ -41,17 +41,17 @@ service::ResolverMap Results::getResolvers() const noexcept }; } -void Results::beginSelectionSet(const service::SelectionSetParams& params) const +void QueryResults::beginSelectionSet(const service::SelectionSetParams& params) const { _pimpl->beginSelectionSet(params); } -void Results::endSelectionSet(const service::SelectionSetParams& params) const +void QueryResults::endSelectionSet(const service::SelectionSetParams& params) const { _pimpl->endSelectionSet(params); } -service::AwaitableResolver Results::resolveData(service::ResolverParams&& params) const +service::AwaitableResolver QueryResults::resolveData(service::ResolverParams&& params) const { std::unique_lock resolverLock(_resolverMutex); service::SelectionSetParams selectionSetParams { static_cast(params) }; @@ -62,7 +62,7 @@ service::AwaitableResolver Results::resolveData(service::ResolverParams&& params return service::ModifiedResult::convert(std::move(result), std::move(params)); } -service::AwaitableResolver Results::resolveErrors(service::ResolverParams&& params) const +service::AwaitableResolver QueryResults::resolveErrors(service::ResolverParams&& params) const { std::unique_lock resolverLock(_resolverMutex); service::SelectionSetParams selectionSetParams { static_cast(params) }; @@ -73,16 +73,16 @@ service::AwaitableResolver Results::resolveErrors(service::ResolverParams&& para return service::ModifiedResult::convert(std::move(result), std::move(params)); } -service::AwaitableResolver Results::resolve_typename(service::ResolverParams&& params) const +service::AwaitableResolver QueryResults::resolve_typename(service::ResolverParams&& params) const { - return service::Result::convert(std::string{ R"gql(Results)gql" }, std::move(params)); + return service::Result::convert(std::string{ R"gql(QueryResults)gql" }, std::move(params)); } } // namespace object -void AddResultsDetails(const std::shared_ptr& typeResults, const std::shared_ptr& schema) +void AddQueryResultsDetails(const std::shared_ptr& typeQueryResults, const std::shared_ptr& schema) { - typeResults->AddFields({ + typeQueryResults->AddFields({ schema::Field::Make(R"gql(data)gql"sv, R"md()md"sv, std::nullopt, schema->LookupType(R"gql(String)gql"sv)), schema::Field::Make(R"gql(errors)gql"sv, R"md()md"sv, std::nullopt, schema->WrapType(introspection::TypeKind::LIST, schema->LookupType(R"gql(String)gql"sv))) }); diff --git a/samples/proxy/schema/ResultsObject.h b/samples/proxy/schema/QueryResultsObject.h similarity index 80% rename from samples/proxy/schema/ResultsObject.h rename to samples/proxy/schema/QueryResultsObject.h index 51718f38..bd4ef01e 100644 --- a/samples/proxy/schema/ResultsObject.h +++ b/samples/proxy/schema/QueryResultsObject.h @@ -5,13 +5,13 @@ #pragma once -#ifndef RESULTSOBJECT_H -#define RESULTSOBJECT_H +#ifndef QUERYRESULTSOBJECT_H +#define QUERYRESULTSOBJECT_H #include "ProxySchema.h" namespace graphql::proxy::object { -namespace methods::ResultsHas { +namespace methods::QueryResultsHas { template concept getDataWithParams = requires (TImpl impl, service::FieldParams params) @@ -49,9 +49,9 @@ concept endSelectionSet = requires (TImpl impl, const service::SelectionSetParam { impl.endSelectionSet(params) }; }; -} // namespace methods::ResultsHas +} // namespace methods::QueryResultsHas -class [[nodiscard("unnecessary construction")]] Results final +class [[nodiscard("unnecessary construction")]] QueryResults final : public service::Object { private: @@ -82,33 +82,33 @@ class [[nodiscard("unnecessary construction")]] Results final [[nodiscard("unnecessary call")]] service::AwaitableScalar> getData(service::FieldParams&& params) const override { - if constexpr (methods::ResultsHas::getDataWithParams) + if constexpr (methods::QueryResultsHas::getDataWithParams) { return { _pimpl->getData(std::move(params)) }; } else { - static_assert(methods::ResultsHas::getData, R"msg(Results::getData is not implemented)msg"); + static_assert(methods::QueryResultsHas::getData, R"msg(QueryResults::getData is not implemented)msg"); return { _pimpl->getData() }; } } [[nodiscard("unnecessary call")]] service::AwaitableScalar>>> getErrors(service::FieldParams&& params) const override { - if constexpr (methods::ResultsHas::getErrorsWithParams) + if constexpr (methods::QueryResultsHas::getErrorsWithParams) { return { _pimpl->getErrors(std::move(params)) }; } else { - static_assert(methods::ResultsHas::getErrors, R"msg(Results::getErrors is not implemented)msg"); + static_assert(methods::QueryResultsHas::getErrors, R"msg(QueryResults::getErrors is not implemented)msg"); return { _pimpl->getErrors() }; } } void beginSelectionSet(const service::SelectionSetParams& params) const override { - if constexpr (methods::ResultsHas::beginSelectionSet) + if constexpr (methods::QueryResultsHas::beginSelectionSet) { _pimpl->beginSelectionSet(params); } @@ -116,7 +116,7 @@ class [[nodiscard("unnecessary construction")]] Results final void endSelectionSet(const service::SelectionSetParams& params) const override { - if constexpr (methods::ResultsHas::endSelectionSet) + if constexpr (methods::QueryResultsHas::endSelectionSet) { _pimpl->endSelectionSet(params); } @@ -126,7 +126,7 @@ class [[nodiscard("unnecessary construction")]] Results final const std::shared_ptr _pimpl; }; - explicit Results(std::unique_ptr pimpl) noexcept; + explicit QueryResults(std::unique_ptr pimpl) noexcept; [[nodiscard("unnecessary call")]] service::TypeNames getTypeNames() const noexcept; [[nodiscard("unnecessary call")]] service::ResolverMap getResolvers() const noexcept; @@ -138,17 +138,17 @@ class [[nodiscard("unnecessary construction")]] Results final public: template - explicit Results(std::shared_ptr pimpl) noexcept - : Results { std::unique_ptr { std::make_unique>(std::move(pimpl)) } } + explicit QueryResults(std::shared_ptr pimpl) noexcept + : QueryResults { std::unique_ptr { std::make_unique>(std::move(pimpl)) } } { } [[nodiscard("unnecessary call")]] static constexpr std::string_view getObjectType() noexcept { - return { R"gql(Results)gql" }; + return { R"gql(QueryResults)gql" }; } }; } // namespace graphql::proxy::object -#endif // RESULTSOBJECT_H +#endif // QUERYRESULTSOBJECT_H diff --git a/samples/proxy/schema/ResultsObject.ixx b/samples/proxy/schema/QueryResultsObject.ixx similarity index 71% rename from samples/proxy/schema/ResultsObject.ixx rename to samples/proxy/schema/QueryResultsObject.ixx index 7f451cc6..27514748 100644 --- a/samples/proxy/schema/ResultsObject.ixx +++ b/samples/proxy/schema/QueryResultsObject.ixx @@ -5,12 +5,12 @@ module; -#include "ResultsObject.h" +#include "QueryResultsObject.h" -export module GraphQL.Proxy.ResultsObject; +export module GraphQL.Proxy.QueryResultsObject; export namespace graphql::proxy::object { -using object::Results; +using object::QueryResults; } // namespace graphql::proxy::object diff --git a/samples/proxy/schema/proxy_schema_files b/samples/proxy/schema/proxy_schema_files index b2805af2..3b54c3a5 100644 --- a/samples/proxy/schema/proxy_schema_files +++ b/samples/proxy/schema/proxy_schema_files @@ -1,3 +1,3 @@ ProxySchema.cpp QueryObject.cpp -ResultsObject.cpp +QueryResultsObject.cpp diff --git a/samples/proxy/schema/schema.graphql b/samples/proxy/schema/schema.graphql index fd32b986..02d9cde0 100644 --- a/samples/proxy/schema/schema.graphql +++ b/samples/proxy/schema/schema.graphql @@ -2,10 +2,23 @@ # Licensed under the MIT License. type Query { - relay(query: String!, operationName: String, variables: String): Results! + relay(input: QueryInput!): QueryResults! } -type Results { +enum OperationType { + QUERY + MUTATION + SUBSCRIPTION +} + +input QueryInput { + type: OperationType! + query: String! + operationName: String = null + variables: String = null +} + +type QueryResults { data: String errors: [String] } diff --git a/src/ClientGenerator.cpp b/src/ClientGenerator.cpp index f8be81e8..8dc873ba 100644 --- a/src/ClientGenerator.cpp +++ b/src/ClientGenerator.cpp @@ -192,7 +192,17 @@ bool Generator::outputHeader() const noexcept #include "graphqlservice/GraphQLResponse.h" #include "graphqlservice/internal/Version.h" +)cpp"; + if (_requestLoader.useSharedTypes()) + { + headerFile << R"cpp( +#include ")cpp" << _schemaLoader.getFilenamePrefix() + << R"cpp(Schema.h" +)cpp"; + } + + headerFile << R"cpp( #include #include #include @@ -220,141 +230,146 @@ static_assert(graphql::internal::MinorVersion == )cpp" outputGetRequestDeclaration(headerFile); const auto& operations = _requestLoader.getOperations(); - std::unordered_set declaredEnum; - for (const auto& operation : operations) + if (!_requestLoader.useSharedTypes()) { - // Define all of the enums referenced either in variables or the response. - for (const auto& enumType : _requestLoader.getReferencedEnums(operation)) - { - const auto cppType = _schemaLoader.getCppType(enumType->name()); + std::unordered_set declaredEnum; - if (!declaredEnum.insert(cppType).second) + for (const auto& operation : operations) + { + // Define all of the enums referenced either in variables or the response. + for (const auto& enumType : _requestLoader.getReferencedEnums(operation)) { - continue; - } + const auto cppType = _schemaLoader.getCppType(enumType->name()); - pendingSeparator.reset(); + if (!declaredEnum.insert(cppType).second) + { + continue; + } - if (clientNamespaceScope.exit()) - { - headerFile << std::endl; - } + pendingSeparator.reset(); + + if (clientNamespaceScope.exit()) + { + headerFile << std::endl; + } - headerFile << R"cpp(enum class [[nodiscard("unnecessary conversion")]] )cpp" << cppType - << R"cpp( + headerFile << R"cpp(enum class [[nodiscard("unnecessary conversion")]] )cpp" + << cppType << R"cpp( { )cpp"; - for (const auto& enumValue : enumType->enumValues()) - { - headerFile << R"cpp( )cpp" << SchemaLoader::getSafeCppName(enumValue->name()) - << R"cpp(, + for (const auto& enumValue : enumType->enumValues()) + { + headerFile << R"cpp( )cpp" << SchemaLoader::getSafeCppName(enumValue->name()) + << R"cpp(, )cpp"; - } + } - headerFile << R"cpp(}; + headerFile << R"cpp(}; )cpp"; - pendingSeparator.add(); + pendingSeparator.add(); + } } - } - std::unordered_set declaredInput; - std::unordered_set forwardDeclaredInput; + std::unordered_set declaredInput; + std::unordered_set forwardDeclaredInput; - for (const auto& operation : operations) - { - // Define all of the input object structs referenced in variables. - for (const auto& inputType : _requestLoader.getReferencedInputTypes(operation)) + for (const auto& operation : operations) { - const auto cppType = _schemaLoader.getCppType(inputType.type->name()); - - if (!declaredInput.insert(cppType).second) + // Define all of the input object structs referenced in variables. + for (const auto& inputType : _requestLoader.getReferencedInputTypes(operation)) { - continue; - } + const auto cppType = _schemaLoader.getCppType(inputType.type->name()); - pendingSeparator.reset(); + if (!declaredInput.insert(cppType).second) + { + continue; + } - if (clientNamespaceScope.exit()) - { - headerFile << std::endl; - } + pendingSeparator.reset(); - if (!inputType.declarations.empty()) - { - // Forward declare nullable dependencies - for (auto declaration : inputType.declarations) + if (clientNamespaceScope.exit()) { - if (declaredInput.find(declaration) == declaredInput.end() - && forwardDeclaredInput.insert(declaration).second) + headerFile << std::endl; + } + + if (!inputType.declarations.empty()) + { + // Forward declare nullable dependencies + for (auto declaration : inputType.declarations) { - headerFile << R"cpp(struct )cpp" << declaration << R"cpp(; + if (declaredInput.find(declaration) == declaredInput.end() + && forwardDeclaredInput.insert(declaration).second) + { + headerFile << R"cpp(struct )cpp" << declaration << R"cpp(; )cpp"; - pendingSeparator.add(); + pendingSeparator.add(); + } } - } - pendingSeparator.reset(); - } + pendingSeparator.reset(); + } - headerFile << R"cpp(struct [[nodiscard("unnecessary construction")]] )cpp" << cppType - << R"cpp( + headerFile << R"cpp(struct [[nodiscard("unnecessary construction")]] )cpp" + << cppType << R"cpp( { explicit )cpp" << cppType - << R"cpp(()cpp"; + << R"cpp(()cpp"; - bool firstField = true; + bool firstField = true; - for (const auto& inputField : inputType.type->inputFields()) - { - if (firstField) + for (const auto& inputField : inputType.type->inputFields()) { - headerFile << R"cpp() noexcept; + if (firstField) + { + headerFile << R"cpp() noexcept; explicit )cpp" << cppType << R"cpp(()cpp"; - } - else - { - headerFile << R"cpp(,)cpp"; - } + } + else + { + headerFile << R"cpp(,)cpp"; + } - firstField = false; + firstField = false; - const auto inputCppType = _requestLoader.getInputCppType(inputField->type().lock()); + const auto inputCppType = + _requestLoader.getInputCppType(inputField->type().lock()); - headerFile << R"cpp( - )cpp" << inputCppType - << R"cpp( )cpp" << SchemaLoader::getSafeCppName(inputField->name()) - << R"cpp(Arg)cpp"; - } + headerFile << R"cpp( + )cpp" << inputCppType << R"cpp( )cpp" + << SchemaLoader::getSafeCppName(inputField->name()) + << R"cpp(Arg)cpp"; + } - headerFile << R"cpp() noexcept; + headerFile << R"cpp() noexcept; )cpp" << cppType << R"cpp((const )cpp" - << cppType << R"cpp(& other); + << cppType << R"cpp(& other); )cpp" << cppType << R"cpp(()cpp" - << cppType << R"cpp(&& other) noexcept; + << cppType << R"cpp(&& other) noexcept; ~)cpp" << cppType << R"cpp((); )cpp" << cppType << R"cpp(& operator=(const )cpp" - << cppType << R"cpp(& other); + << cppType << R"cpp(& other); )cpp" << cppType << R"cpp(& operator=()cpp" - << cppType << R"cpp(&& other) noexcept; + << cppType << R"cpp(&& other) noexcept; )cpp"; - for (const auto& inputField : inputType.type->inputFields()) - { - headerFile << R"cpp( )cpp" - << _requestLoader.getInputCppType(inputField->type().lock()) - << R"cpp( )cpp" << SchemaLoader::getSafeCppName(inputField->name()) - << R"cpp(; + for (const auto& inputField : inputType.type->inputFields()) + { + headerFile << R"cpp( )cpp" + << _requestLoader.getInputCppType(inputField->type().lock()) + << R"cpp( )cpp" << SchemaLoader::getSafeCppName(inputField->name()) + << R"cpp(; )cpp"; - } + } - headerFile << R"cpp(}; + headerFile << R"cpp(}; )cpp"; - pendingSeparator.add(); + pendingSeparator.add(); + } } } @@ -855,164 +870,170 @@ using namespace std::literals; outputGetRequestImplementation(sourceFile); const auto& operations = _requestLoader.getOperations(); - std::unordered_set outputInputMethods; - for (const auto& operation : operations) + if (!_requestLoader.useSharedTypes()) { - for (const auto& inputType : _requestLoader.getReferencedInputTypes(operation)) - { - const auto cppType = _schemaLoader.getCppType(inputType.type->name()); - if (!outputInputMethods.insert(cppType).second) + std::unordered_set outputInputMethods; + + for (const auto& operation : operations) + { + for (const auto& inputType : _requestLoader.getReferencedInputTypes(operation)) { - continue; - } + const auto cppType = _schemaLoader.getCppType(inputType.type->name()); - pendingSeparator.reset(); + if (!outputInputMethods.insert(cppType).second) + { + continue; + } - if (clientNamespaceScope.exit()) - { - sourceFile << R"cpp( -using namespace graphql::)cpp" - << getClientNamespace() << R"cpp(; + pendingSeparator.reset(); + + if (clientNamespaceScope.exit()) + { + sourceFile << R"cpp( +using namespace graphql::)cpp" << getClientNamespace() + << R"cpp(; )cpp"; - } + } - sourceFile << cppType << R"cpp(::)cpp" << cppType << R"cpp(() noexcept)cpp"; + sourceFile << cppType << R"cpp(::)cpp" << cppType << R"cpp(() noexcept)cpp"; - bool firstField = true; + bool firstField = true; - for (const auto& inputField : inputType.type->inputFields()) - { - sourceFile << R"cpp( + for (const auto& inputField : inputType.type->inputFields()) + { + sourceFile << R"cpp( )cpp" << (firstField ? R"cpp(:)cpp" : R"cpp(,)cpp") - << R"cpp( )cpp" << SchemaLoader::getSafeCppName(inputField->name()) - << R"cpp( {})cpp"; - firstField = false; - } + << R"cpp( )cpp" << SchemaLoader::getSafeCppName(inputField->name()) + << R"cpp( {})cpp"; + firstField = false; + } - sourceFile << R"cpp( + sourceFile << R"cpp( { // Explicit definition to prevent ODR violations when LTO is enabled. } )cpp" << cppType << R"cpp(::)cpp" - << cppType << R"cpp(()cpp"; + << cppType << R"cpp(()cpp"; - firstField = true; + firstField = true; - for (const auto& inputField : inputType.type->inputFields()) - { - if (!firstField) + for (const auto& inputField : inputType.type->inputFields()) { - sourceFile << R"cpp(,)cpp"; - } + if (!firstField) + { + sourceFile << R"cpp(,)cpp"; + } - firstField = false; - sourceFile << R"cpp( + firstField = false; + sourceFile << R"cpp( )cpp" << _requestLoader.getInputCppType(inputField->type().lock()) - << R"cpp( )cpp" << SchemaLoader::getSafeCppName(inputField->name()) - << R"cpp(Arg)cpp"; - } + << R"cpp( )cpp" << SchemaLoader::getSafeCppName(inputField->name()) + << R"cpp(Arg)cpp"; + } - sourceFile << R"cpp() noexcept + sourceFile << R"cpp() noexcept )cpp"; - firstField = true; + firstField = true; - for (const auto& inputField : inputType.type->inputFields()) - { - sourceFile << (firstField ? R"cpp( : )cpp" : R"cpp( , )cpp"); - firstField = false; + for (const auto& inputField : inputType.type->inputFields()) + { + sourceFile << (firstField ? R"cpp( : )cpp" : R"cpp( , )cpp"); + firstField = false; - const auto name = SchemaLoader::getSafeCppName(inputField->name()); + const auto name = SchemaLoader::getSafeCppName(inputField->name()); - sourceFile << name << R"cpp( { std::move()cpp" << name << R"cpp(Arg) } + sourceFile << name << R"cpp( { std::move()cpp" << name << R"cpp(Arg) } )cpp"; - } + } - sourceFile << R"cpp({ + sourceFile << R"cpp({ } )cpp" << cppType << R"cpp(::)cpp" - << cppType << R"cpp((const )cpp" << cppType << R"cpp(& other) + << cppType << R"cpp((const )cpp" << cppType << R"cpp(& other) )cpp"; - firstField = true; + firstField = true; - for (const auto& inputField : inputType.type->inputFields()) - { - sourceFile << (firstField ? R"cpp( : )cpp" : R"cpp( , )cpp"); - firstField = false; + for (const auto& inputField : inputType.type->inputFields()) + { + sourceFile << (firstField ? R"cpp( : )cpp" : R"cpp( , )cpp"); + firstField = false; - const auto name = SchemaLoader::getSafeCppName(inputField->name()); - const auto [type, modifiers] = - RequestLoader::unwrapSchemaType(inputField->type().lock()); + const auto name = SchemaLoader::getSafeCppName(inputField->name()); + const auto [type, modifiers] = + RequestLoader::unwrapSchemaType(inputField->type().lock()); - sourceFile << name << R"cpp( { ModifiedVariable<)cpp" - << _schemaLoader.getCppType(type->name()) << R"cpp(>::duplicate)cpp" - << getTypeModifierList(modifiers) << R"cpp((other.)cpp" << name - << R"cpp() } + sourceFile << name << R"cpp( { ModifiedVariable<)cpp" + << _schemaLoader.getCppType(type->name()) << R"cpp(>::duplicate)cpp" + << getTypeModifierList(modifiers) << R"cpp((other.)cpp" << name + << R"cpp() } )cpp"; - } + } - sourceFile << R"cpp({ + sourceFile << R"cpp({ } )cpp" << cppType << R"cpp(::)cpp" - << cppType << R"cpp(()cpp" << cppType << R"cpp(&& other) noexcept + << cppType << R"cpp(()cpp" << cppType << R"cpp(&& other) noexcept )cpp"; - firstField = true; + firstField = true; - for (const auto& inputField : inputType.type->inputFields()) - { - sourceFile << (firstField ? R"cpp( : )cpp" : R"cpp( , )cpp"); - firstField = false; + for (const auto& inputField : inputType.type->inputFields()) + { + sourceFile << (firstField ? R"cpp( : )cpp" : R"cpp( , )cpp"); + firstField = false; - const auto name = SchemaLoader::getSafeCppName(inputField->name()); + const auto name = SchemaLoader::getSafeCppName(inputField->name()); - sourceFile << name << R"cpp( { std::move(other.)cpp" << name << R"cpp() } + sourceFile << name << R"cpp( { std::move(other.)cpp" << name << R"cpp() } )cpp"; - } + } - sourceFile << R"cpp({ + sourceFile << R"cpp({ } )cpp" << cppType << R"cpp(::~)cpp" - << cppType << R"cpp(() + << cppType << R"cpp(() { // Explicit definition to prevent ODR violations when LTO is enabled. } )cpp" << cppType << R"cpp(& )cpp" - << cppType << R"cpp(::operator=(const )cpp" << cppType << R"cpp(& other) + << cppType << R"cpp(::operator=(const )cpp" << cppType << R"cpp(& other) { - return *this = )cpp" - << cppType << R"cpp( { other }; + return *this = )cpp" << cppType + << R"cpp( { other }; } )cpp" << cppType << R"cpp(& )cpp" - << cppType << R"cpp(::operator=()cpp" << cppType << R"cpp(&& other) noexcept + << cppType << R"cpp(::operator=()cpp" << cppType + << R"cpp(&& other) noexcept { )cpp"; - for (const auto& inputField : inputType.type->inputFields()) - { - const auto name = SchemaLoader::getSafeCppName(inputField->name()); + for (const auto& inputField : inputType.type->inputFields()) + { + const auto name = SchemaLoader::getSafeCppName(inputField->name()); - sourceFile << R"cpp( )cpp" << name << R"cpp( = std::move(other.)cpp" << name - << R"cpp(); + sourceFile << R"cpp( )cpp" << name << R"cpp( = std::move(other.)cpp" << name + << R"cpp(); )cpp"; - } + } - sourceFile << R"cpp( + sourceFile << R"cpp( return *this; } )cpp"; - pendingSeparator.add(); + pendingSeparator.add(); + } } } @@ -1586,6 +1607,7 @@ int main(int argc, char** argv) bool buildCustom = false; bool verbose = false; bool noIntrospection = false; + bool sharedTypes = false; std::string schemaFileName; std::string requestFileName; std::string operationName; @@ -1615,7 +1637,9 @@ int main(int argc, char** argv) po::value(&headerDir), "Target path for the Client.h header file")("no-introspection", po::bool_switch(&noIntrospection), - "Do not expect support for Introspection"); + "Do not expect support for Introspection")("shared-types", + po::bool_switch(&sharedTypes), + "Re-use shared types from Schema.h"); positional.add("schema", 1).add("request", 1).add("prefix", 1).add("namespace", 1); try @@ -1677,6 +1701,7 @@ int main(int argc, char** argv) { operationName.empty() ? std::nullopt : std::make_optional(std::move(operationName)) }, noIntrospection, + sharedTypes, }, graphql::generator::client::GeneratorOptions { { std::move(headerDir), std::move(sourceDir) }, diff --git a/src/RequestLoader.cpp b/src/RequestLoader.cpp index 0e59f661..e4d3d7c4 100644 --- a/src/RequestLoader.cpp +++ b/src/RequestLoader.cpp @@ -140,6 +140,11 @@ const RequestVariableList& RequestLoader::getVariables(const Operation& operatio return operation.variables; } +bool RequestLoader::useSharedTypes() const noexcept +{ + return _requestOptions.sharedTypes; +} + const RequestInputTypeList& RequestLoader::getReferencedInputTypes( const Operation& operation) const noexcept { From 1769f19a9337f3bb976367155ffa4be75de5a9a5 Mon Sep 17 00:00:00 2001 From: Bill Avery Date: Thu, 19 Sep 2024 15:19:05 -0700 Subject: [PATCH 3/4] feat(sharetypes): enable shared types for client benchmark --- samples/client/CMakeLists.txt | 1 - samples/client/benchmark.cpp | 5 ++- samples/client/benchmark/CMakeLists.txt | 3 +- .../{BenchmarkClient.cpp => TodayClient.cpp} | 34 +++++++++---------- .../{BenchmarkClient.h => TodayClient.h} | 16 +++++---- .../{BenchmarkClient.ixx => TodayClient.ixx} | 12 +++---- .../client/benchmark/benchmark_client_files | 2 +- src/ClientGenerator.cpp | 3 +- 8 files changed, 39 insertions(+), 37 deletions(-) rename samples/client/benchmark/{BenchmarkClient.cpp => TodayClient.cpp} (64%) rename samples/client/benchmark/{BenchmarkClient.h => TodayClient.h} (92%) rename samples/client/benchmark/{BenchmarkClient.ixx => TodayClient.ixx} (64%) diff --git a/samples/client/CMakeLists.txt b/samples/client/CMakeLists.txt index a001c133..09a6036e 100644 --- a/samples/client/CMakeLists.txt +++ b/samples/client/CMakeLists.txt @@ -15,7 +15,6 @@ if(GRAPHQL_BUILD_MODULES) # client_benchmark add_executable(client_benchmark benchmark.cpp) target_link_libraries(client_benchmark PRIVATE - todaygraphql benchmark_client) if(WIN32 AND BUILD_SHARED_LIBS) diff --git a/samples/client/benchmark.cpp b/samples/client/benchmark.cpp index bd699ea8..66723db2 100644 --- a/samples/client/benchmark.cpp +++ b/samples/client/benchmark.cpp @@ -16,8 +16,7 @@ import GraphQL.Client; import GraphQL.Service; import GraphQL.Today.Mock; - -import GraphQL.Benchmark.BenchmarkClient; +import GraphQL.Today.TodayClient; using namespace graphql; @@ -93,7 +92,7 @@ int main(int argc, char** argv) try { - using namespace benchmark::client::query::Query; + using namespace today::client::query::Query; auto query = GetRequestObject(); const auto& name = GetOperationName(); diff --git a/samples/client/benchmark/CMakeLists.txt b/samples/client/benchmark/CMakeLists.txt index c2ec979e..dc132942 100644 --- a/samples/client/benchmark/CMakeLists.txt +++ b/samples/client/benchmark/CMakeLists.txt @@ -7,7 +7,8 @@ cmake_minimum_required(VERSION 3.28) include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/cppgraphqlgen-functions.cmake) if(GRAPHQL_UPDATE_SAMPLES AND GRAPHQL_BUILD_CLIENTGEN) - update_graphql_client_files(benchmark ../../today/schema.today.graphql client.benchmark.today.graphql Benchmark benchmark) + update_graphql_client_files(benchmark ../../today/schema.today.graphql client.benchmark.today.graphql Today today --shared-types) endif() add_graphql_client_target(benchmark) +target_link_libraries(benchmark_client PRIVATE todaygraphql) diff --git a/samples/client/benchmark/BenchmarkClient.cpp b/samples/client/benchmark/TodayClient.cpp similarity index 64% rename from samples/client/benchmark/BenchmarkClient.cpp rename to samples/client/benchmark/TodayClient.cpp index 0f9fb48b..0f65eae7 100644 --- a/samples/client/benchmark/BenchmarkClient.cpp +++ b/samples/client/benchmark/TodayClient.cpp @@ -3,7 +3,7 @@ // WARNING! Do not edit this file manually, your changes will be overwritten. -#include "BenchmarkClient.h" +#include "TodayClient.h" #include "graphqlservice/internal/SortedMap.h" @@ -17,7 +17,7 @@ using namespace std::literals; namespace graphql { -namespace benchmark { +namespace today { namespace client { const std::string& GetRequestText() noexcept @@ -61,15 +61,15 @@ const peg::ast& GetRequestObject() noexcept } } // namespace client -} // namespace benchmark +} // namespace today namespace client { -using namespace benchmark; +using namespace today; template <> -graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection::pageInfo_PageInfo Response::parse(response::Value&& response) +graphql::today::client::query::Query::Response::appointments_AppointmentConnection::pageInfo_PageInfo Response::parse(response::Value&& response) { - graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection::pageInfo_PageInfo result; + graphql::today::client::query::Query::Response::appointments_AppointmentConnection::pageInfo_PageInfo result; if (response.type() == response::Type::Map) { @@ -89,9 +89,9 @@ graphql::benchmark::client::query::Query::Response::appointments_AppointmentConn } template <> -graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment Response::parse(response::Value&& response) +graphql::today::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment Response::parse(response::Value&& response) { - graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment result; + graphql::today::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge::node_Appointment result; if (response.type() == response::Type::Map) { @@ -126,9 +126,9 @@ graphql::benchmark::client::query::Query::Response::appointments_AppointmentConn } template <> -graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge Response::parse(response::Value&& response) +graphql::today::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge Response::parse(response::Value&& response) { - graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge result; + graphql::today::client::query::Query::Response::appointments_AppointmentConnection::edges_AppointmentEdge result; if (response.type() == response::Type::Map) { @@ -138,7 +138,7 @@ graphql::benchmark::client::query::Query::Response::appointments_AppointmentConn { if (member.first == R"js(node)js"sv) { - result.node = ModifiedResponse::parse(std::move(member.second)); + result.node = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -148,9 +148,9 @@ graphql::benchmark::client::query::Query::Response::appointments_AppointmentConn } template <> -graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection Response::parse(response::Value&& response) +graphql::today::client::query::Query::Response::appointments_AppointmentConnection Response::parse(response::Value&& response) { - graphql::benchmark::client::query::Query::Response::appointments_AppointmentConnection result; + graphql::today::client::query::Query::Response::appointments_AppointmentConnection result; if (response.type() == response::Type::Map) { @@ -160,12 +160,12 @@ graphql::benchmark::client::query::Query::Response::appointments_AppointmentConn { if (member.first == R"js(pageInfo)js"sv) { - result.pageInfo = ModifiedResponse::parse(std::move(member.second)); + result.pageInfo = ModifiedResponse::parse(std::move(member.second)); continue; } if (member.first == R"js(edges)js"sv) { - result.edges = ModifiedResponse::parse(std::move(member.second)); + result.edges = ModifiedResponse::parse(std::move(member.second)); continue; } } @@ -176,7 +176,7 @@ graphql::benchmark::client::query::Query::Response::appointments_AppointmentConn } // namespace client -namespace benchmark::client::query::Query { +namespace today::client::query::Query { const std::string& GetOperationName() noexcept { @@ -228,5 +228,5 @@ Response parseResponse(response::Value&& response) return Query::parseResponse(std::move(response)); } -} // namespace benchmark::client::query::Query +} // namespace today::client::query::Query } // namespace graphql diff --git a/samples/client/benchmark/BenchmarkClient.h b/samples/client/benchmark/TodayClient.h similarity index 92% rename from samples/client/benchmark/BenchmarkClient.h rename to samples/client/benchmark/TodayClient.h index 8c0981a9..d0f74413 100644 --- a/samples/client/benchmark/BenchmarkClient.h +++ b/samples/client/benchmark/TodayClient.h @@ -5,8 +5,8 @@ #pragma once -#ifndef BENCHMARKCLIENT_H -#define BENCHMARKCLIENT_H +#ifndef TODAYCLIENT_H +#define TODAYCLIENT_H #include "graphqlservice/GraphQLClient.h" #include "graphqlservice/GraphQLParse.h" @@ -14,6 +14,8 @@ #include "graphqlservice/internal/Version.h" +#include "TodaySchema.h" + #include #include #include @@ -22,7 +24,7 @@ static_assert(graphql::internal::MajorVersion == 5, "regenerate with clientgen: major version mismatch"); static_assert(graphql::internal::MinorVersion == 0, "regenerate with clientgen: minor version mismatch"); -namespace graphql::benchmark { +namespace graphql::today { /// # Operation: query (unnamed) /// ```graphql @@ -55,8 +57,8 @@ namespace client { namespace query::Query { -using graphql::benchmark::client::GetRequestText; -using graphql::benchmark::client::GetRequestObject; +using graphql::today::client::GetRequestText; +using graphql::today::client::GetRequestObject; // Return the name of this operation in the shared request document. [[nodiscard("unnecessary call")]] const std::string& GetOperationName() noexcept; @@ -105,6 +107,6 @@ struct Traits } // namespace query::Query } // namespace client -} // namespace graphql::benchmark +} // namespace graphql::today -#endif // BENCHMARKCLIENT_H +#endif // TODAYCLIENT_H diff --git a/samples/client/benchmark/BenchmarkClient.ixx b/samples/client/benchmark/TodayClient.ixx similarity index 64% rename from samples/client/benchmark/BenchmarkClient.ixx rename to samples/client/benchmark/TodayClient.ixx index 4ab91474..5631ad46 100644 --- a/samples/client/benchmark/BenchmarkClient.ixx +++ b/samples/client/benchmark/TodayClient.ixx @@ -5,11 +5,11 @@ module; -#include "BenchmarkClient.h" +#include "TodayClient.h" -export module GraphQL.Benchmark.BenchmarkClient; +export module GraphQL.Today.TodayClient; -export namespace graphql::benchmark { +export namespace graphql::today { namespace client { @@ -18,8 +18,8 @@ using client::GetRequestObject; namespace query::Query { -using graphql::benchmark::client::GetRequestText; -using graphql::benchmark::client::GetRequestObject; +using graphql::today::client::GetRequestText; +using graphql::today::client::GetRequestObject; using Query::GetOperationName; using Query::Response; @@ -30,4 +30,4 @@ using Query::Traits; } // namespace query::Query } // namespace client -} // namespace graphql::benchmark +} // namespace graphql::today diff --git a/samples/client/benchmark/benchmark_client_files b/samples/client/benchmark/benchmark_client_files index 2d3350f3..995e48c6 100644 --- a/samples/client/benchmark/benchmark_client_files +++ b/samples/client/benchmark/benchmark_client_files @@ -1 +1 @@ -BenchmarkClient.cpp +TodayClient.cpp diff --git a/src/ClientGenerator.cpp b/src/ClientGenerator.cpp index 8dc873ba..69ba95ba 100644 --- a/src/ClientGenerator.cpp +++ b/src/ClientGenerator.cpp @@ -1134,7 +1134,8 @@ using namespace )cpp" << _schemaLoader.getSchemaNamespace() sourceFile << R"cpp(template <> response::Value Variable<)cpp" - << cppType << R"cpp(>::serialize()cpp" << cppType << R"cpp(&& inputValue) + << cppType << R"cpp(>::serialize()cpp" << cppType + << R"cpp(&& inputValue) { response::Value result { response::Type::Map }; From 4e0cc8c30e69a7d5a7751ae3ac6f774673110625 Mon Sep 17 00:00:00 2001 From: Bill Avery Date: Thu, 19 Sep 2024 15:27:22 -0700 Subject: [PATCH 4/4] fix(CI): samples/client/benchmark dir needs module support --- samples/client/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/client/CMakeLists.txt b/samples/client/CMakeLists.txt index 09a6036e..f7a69a70 100644 --- a/samples/client/CMakeLists.txt +++ b/samples/client/CMakeLists.txt @@ -9,10 +9,9 @@ add_subdirectory(subscribe) add_subdirectory(nestedinput) add_subdirectory(multiple) -add_subdirectory(benchmark) - if(GRAPHQL_BUILD_MODULES) # client_benchmark + add_subdirectory(benchmark) add_executable(client_benchmark benchmark.cpp) target_link_libraries(client_benchmark PRIVATE benchmark_client)