From 2d8ea000ab45c6dc62e917c1da3636a80963a8d3 Mon Sep 17 00:00:00 2001 From: Bill Avery Date: Mon, 16 Sep 2024 10:04:09 -0700 Subject: [PATCH 1/5] fix(cmake): installed targets don't preserve target properties --- cmake/cppgraphqlgen-functions.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/cppgraphqlgen-functions.cmake b/cmake/cppgraphqlgen-functions.cmake index 3b5d1615..f17a1ff0 100644 --- a/cmake/cppgraphqlgen-functions.cmake +++ b/cmake/cppgraphqlgen-functions.cmake @@ -53,7 +53,7 @@ function(add_graphql_schema_target SCHEMA_TARGET) target_sources(${SCHEMA_TARGET}_schema PUBLIC FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SCHEMA_HEADERS}) - get_target_property(GRAPHQL_BUILD_MODULES cppgraphqlgen::graphqlservice GRAPHQL_BUILD_MODULES) + get_target_property(GRAPHQL_BUILD_MODULES cppgraphqlgen::graphqlservice INTERFACE_CXX_MODULE_SETS) if(GRAPHQL_BUILD_MODULES) file(GLOB SCHEMA_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/*.ixx) target_sources(${SCHEMA_TARGET}_schema PUBLIC FILE_SET CXX_MODULES @@ -107,7 +107,7 @@ function(add_graphql_client_target CLIENT_TARGET) target_sources(${CLIENT_TARGET}_client PUBLIC FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} FILES ${CLIENT_HEADERS}) - get_target_property(GRAPHQL_BUILD_MODULES cppgraphqlgen::graphqlclient GRAPHQL_BUILD_MODULES) + get_target_property(GRAPHQL_BUILD_MODULES cppgraphqlgen::graphqlclient INTERFACE_CXX_MODULE_SETS) if(GRAPHQL_BUILD_MODULES) file(GLOB CLIENT_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/*.ixx) target_sources(${CLIENT_TARGET}_client PUBLIC FILE_SET CXX_MODULES From 87258e02ed287db4503734a69f08b0b6e57c41d1 Mon Sep 17 00:00:00 2001 From: Bill Avery Date: Mon, 16 Sep 2024 10:12:11 -0700 Subject: [PATCH 2/5] fix(cmake): drop unnecessary set_target_properties --- src/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 307a9325..64d1d21f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -337,7 +337,6 @@ if(GRAPHQL_BUILD_MODULES) target_sources(graphqlservice PUBLIC FILE_SET CXX_MODULES BASE_DIRS ${INCLUDE_ROOT} FILES ${INCLUDE_ROOT}/graphqlservice/Service.ixx) - set_target_properties(graphqlservice PROPERTIES GRAPHQL_BUILD_MODULES ON) endif() if(GRAPHQL_UPDATE_SAMPLES) @@ -374,7 +373,6 @@ if(GRAPHQL_BUILD_MODULES) target_sources(graphqlclient PUBLIC FILE_SET CXX_MODULES BASE_DIRS ${INCLUDE_ROOT} FILES ${INCLUDE_ROOT}/graphqlservice/Client.ixx) - set_target_properties(graphqlclient PROPERTIES GRAPHQL_BUILD_MODULES ON) endif() if(GRAPHQL_UPDATE_VERSION) From 7c3e3a8beb0b27e2e8eef084333956bc48a504e1 Mon Sep 17 00:00:00 2001 From: Bill Avery Date: Mon, 16 Sep 2024 15:36:34 -0700 Subject: [PATCH 3/5] feat(ranges): start adopting ranges --- include/graphqlservice/GraphQLClient.h | 8 +-- include/graphqlservice/GraphQLService.h | 7 ++- samples/client/benchmark.cpp | 3 +- samples/learn/DroidData.cpp | 39 +++++-------- samples/learn/HumanData.cpp | 39 +++++-------- samples/today/TodayMock.cpp | 66 ++++++++-------------- samples/today/benchmark.cpp | 3 +- src/ClientGenerator.cpp | 11 ++-- src/GeneratorUtil.cpp | 20 +++---- src/GraphQLClient.cpp | 9 +-- src/GraphQLResponse.cpp | 12 ++-- src/GraphQLService.cpp | 23 +++----- src/Introspection.cpp | 27 ++++----- src/RequestLoader.cpp | 75 ++++++++++--------------- src/Schema.cpp | 9 +-- src/SchemaGenerator.cpp | 15 ++--- src/SchemaLoader.cpp | 30 +++++----- src/Validation.cpp | 3 +- test/ResponseTests.cpp | 4 +- 19 files changed, 166 insertions(+), 237 deletions(-) diff --git a/include/graphqlservice/GraphQLClient.h b/include/graphqlservice/GraphQLClient.h index afc0caa2..a1f5b5d7 100644 --- a/include/graphqlservice/GraphQLClient.h +++ b/include/graphqlservice/GraphQLClient.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -167,7 +168,7 @@ struct ModifiedVariable response::Value result { response::Type::List }; result.reserve(listValue.size()); - std::for_each(listValue.begin(), listValue.end(), [&result](auto& value) { + std::ranges::for_each(listValue, [&result](auto& value) { result.emplace_back(serialize(std::move(value))); }); listValue.clear(); @@ -218,7 +219,7 @@ struct ModifiedVariable { typename VariableTraits::type result(listValue.size()); - std::transform(listValue.cbegin(), listValue.cend(), result.begin(), duplicate); + std::ranges::transform(listValue, result.begin(), duplicate); return result; } @@ -322,8 +323,7 @@ struct ModifiedResponse auto listValue = response.release(); result.reserve(listValue.size()); - std::transform(listValue.begin(), - listValue.end(), + std::ranges::transform(listValue, std::back_inserter(result), [](response::Value& value) { return parse(std::move(value)); diff --git a/include/graphqlservice/GraphQLService.h b/include/graphqlservice/GraphQLService.h index 9561eb86..b6c84687 100644 --- a/include/graphqlservice/GraphQLService.h +++ b/include/graphqlservice/GraphQLService.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -758,8 +759,8 @@ struct ModifiedArgument typename ArgumentTraits::type result(values.size()); const auto& elements = values.get(); - std::transform(elements.cbegin(), - elements.cend(), + std::transform(elements.begin(), + elements.end(), result.begin(), [name](const response::Value& element) { response::Value single(response::Type::Map); @@ -831,7 +832,7 @@ struct ModifiedArgument { typename ArgumentTraits::type result(listValue.size()); - std::transform(listValue.cbegin(), listValue.cend(), result.begin(), duplicate); + std::ranges::transform(listValue, result.begin(), duplicate); return result; } diff --git a/samples/client/benchmark.cpp b/samples/client/benchmark.cpp index 10c56b13..73ce8780 100644 --- a/samples/client/benchmark.cpp +++ b/samples/client/benchmark.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,7 @@ void outputOverview( void outputSegment( std::string_view name, std::vector& durations) noexcept { - std::sort(durations.begin(), durations.end()); + std::ranges::sort(durations); const auto count = durations.size(); const auto total = diff --git a/samples/learn/DroidData.cpp b/samples/learn/DroidData.cpp index ee3d9548..2f40ed22 100644 --- a/samples/learn/DroidData.cpp +++ b/samples/learn/DroidData.cpp @@ -21,18 +21,15 @@ void Droid::addFriends( { friends_.resize(friends.size()); - std::transform(friends.begin(), - friends.end(), - friends_.begin(), - [](const auto& spFriend) noexcept { - return std::visit( - [](const auto& hero) noexcept { - return WeakHero { - std::weak_ptr::element_type> { hero } - }; - }, - spFriend); - }); + std::ranges::transform(friends, friends_.begin(), [](const auto& spFriend) noexcept { + return std::visit( + [](const auto& hero) noexcept { + return WeakHero { + std::weak_ptr::element_type> { hero } + }; + }, + spFriend); + }); } const response::IdType& Droid::getId() const noexcept @@ -49,12 +46,9 @@ std::optional>> Droid::getFriends { std::vector> result(friends_.size()); - std::transform(friends_.begin(), - friends_.end(), - result.begin(), - [](const auto& wpFriend) noexcept { - return make_hero(wpFriend); - }); + std::ranges::transform(friends_, result.begin(), [](const auto& wpFriend) noexcept { + return make_hero(wpFriend); + }); result.erase(std::remove(result.begin(), result.end(), std::shared_ptr {}), result.end()); @@ -65,12 +59,9 @@ std::optional>> Droid::getAppearsIn() const n { std::vector> result(appearsIn_.size()); - std::transform(appearsIn_.begin(), - appearsIn_.end(), - result.begin(), - [](const auto& entry) noexcept { - return std::make_optional(entry); - }); + std::ranges::transform(appearsIn_, result.begin(), [](const auto& entry) noexcept { + return std::make_optional(entry); + }); return result.empty() ? std::nullopt : std::make_optional(std::move(result)); } diff --git a/samples/learn/HumanData.cpp b/samples/learn/HumanData.cpp index 486ce9aa..b9489763 100644 --- a/samples/learn/HumanData.cpp +++ b/samples/learn/HumanData.cpp @@ -20,18 +20,15 @@ void Human::addFriends(std::vector friends) noexcept { friends_.resize(friends.size()); - std::transform(friends.begin(), - friends.end(), - friends_.begin(), - [](const auto& spFriend) noexcept { - return std::visit( - [](const auto& hero) noexcept { - return WeakHero { - std::weak_ptr::element_type> { hero } - }; - }, - spFriend); - }); + std::ranges::transform(friends, friends_.begin(), [](const auto& spFriend) noexcept { + return std::visit( + [](const auto& hero) noexcept { + return WeakHero { + std::weak_ptr::element_type> { hero } + }; + }, + spFriend); + }); } const response::IdType& Human::getId() const noexcept @@ -48,12 +45,9 @@ std::optional>> Human::getFriends { std::vector> result(friends_.size()); - std::transform(friends_.begin(), - friends_.end(), - result.begin(), - [](const auto& wpFriend) noexcept { - return make_hero(wpFriend); - }); + std::ranges::transform(friends_, result.begin(), [](const auto& wpFriend) noexcept { + return make_hero(wpFriend); + }); result.erase(std::remove(result.begin(), result.end(), std::shared_ptr {}), result.end()); @@ -64,12 +58,9 @@ std::optional>> Human::getAppearsIn() const n { std::vector> result(appearsIn_.size()); - std::transform(appearsIn_.begin(), - appearsIn_.end(), - result.begin(), - [](const auto& entry) noexcept { - return std::make_optional(entry); - }); + std::ranges::transform(appearsIn_, result.begin(), [](const auto& entry) noexcept { + return std::make_optional(entry); + }); return result.empty() ? std::nullopt : std::make_optional(std::move(result)); } diff --git a/samples/today/TodayMock.cpp b/samples/today/TodayMock.cpp index 53b0b35b..d7464511 100644 --- a/samples/today/TodayMock.cpp +++ b/samples/today/TodayMock.cpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace graphql::today { @@ -24,7 +25,7 @@ const response::IdType& getFakeAppointmentId() noexcept std::string_view fakeIdString { "fakeAppointmentId" }; response::IdType result(fakeIdString.size()); - std::copy(fakeIdString.cbegin(), fakeIdString.cend(), result.begin()); + std::ranges::copy(fakeIdString, result.begin()); return response::IdType { std::move(result) }; }(); @@ -38,7 +39,7 @@ const response::IdType& getFakeTaskId() noexcept std::string_view fakeIdString { "fakeTaskId" }; response::IdType result(fakeIdString.size()); - std::copy(fakeIdString.cbegin(), fakeIdString.cend(), result.begin()); + std::ranges::copy(fakeIdString, result.begin()); return response::IdType { std::move(result) }; }(); @@ -52,7 +53,7 @@ const response::IdType& getFakeFolderId() noexcept std::string_view fakeIdString { "fakeFolderId" }; response::IdType result(fakeIdString.size()); - std::copy(fakeIdString.cbegin(), fakeIdString.cend(), result.begin()); + std::ranges::copy(fakeIdString, result.begin()); return response::IdType { std::move(result) }; }(); @@ -198,8 +199,7 @@ std::optional>> Appointment auto result = std::make_optional>>( _appointments.size()); - std::transform(_appointments.cbegin(), - _appointments.cend(), + std::ranges::transform(_appointments, result->begin(), [](const std::shared_ptr& node) { return std::make_shared( @@ -268,12 +268,9 @@ std::optional>> TaskConnection::ge { auto result = std::make_optional>>(_tasks.size()); - std::transform(_tasks.cbegin(), - _tasks.cend(), - result->begin(), - [](const std::shared_ptr& node) { - return std::make_shared(std::make_shared(node)); - }); + std::ranges::transform(_tasks, result->begin(), [](const std::shared_ptr& node) { + return std::make_shared(std::make_shared(node)); + }); return result; } @@ -338,12 +335,9 @@ std::optional>> FolderConnection auto result = std::make_optional>>(_folders.size()); - std::transform(_folders.cbegin(), - _folders.cend(), - result->begin(), - [](const std::shared_ptr& node) { - return std::make_shared(std::make_shared(node)); - }); + std::ranges::transform(_folders, result->begin(), [](const std::shared_ptr& node) { + return std::make_shared(std::make_shared(node)); + }); return result; } @@ -708,12 +702,9 @@ std::vector> Query::getAppointmentsById( { std::vector> result(ids.size()); - std::transform(ids.cbegin(), - ids.cend(), - result.begin(), - [this, ¶ms](const response::IdType& id) { - return std::make_shared(findAppointment(params, id)); - }); + std::ranges::transform(ids, result.begin(), [this, ¶ms](const response::IdType& id) { + return std::make_shared(findAppointment(params, id)); + }); return result; } @@ -723,12 +714,9 @@ std::vector> Query::getTasksById( { std::vector> result(ids.size()); - std::transform(ids.cbegin(), - ids.cend(), - result.begin(), - [this, ¶ms](const response::IdType& id) { - return std::make_shared(findTask(params, id)); - }); + std::ranges::transform(ids, result.begin(), [this, ¶ms](const response::IdType& id) { + return std::make_shared(findTask(params, id)); + }); return result; } @@ -738,12 +726,9 @@ std::vector> Query::getUnreadCountsById( { std::vector> result(ids.size()); - std::transform(ids.cbegin(), - ids.cend(), - result.begin(), - [this, ¶ms](const response::IdType& id) { - return std::make_shared(findUnreadCount(params, id)); - }); + std::ranges::transform(ids, result.begin(), [this, ¶ms](const response::IdType& id) { + return std::make_shared(findUnreadCount(params, id)); + }); return result; } @@ -777,13 +762,10 @@ std::vector> Query::getAnyType( std::vector> result(_appointments.size()); - std::transform(_appointments.cbegin(), - _appointments.cend(), - result.begin(), - [](const auto& appointment) noexcept { - return std::make_shared( - std::make_shared(appointment)); - }); + std::ranges::transform(_appointments, result.begin(), [](const auto& appointment) noexcept { + return std::make_shared( + std::make_shared(appointment)); + }); return result; } diff --git a/samples/today/benchmark.cpp b/samples/today/benchmark.cpp index bec9c86d..4442135c 100644 --- a/samples/today/benchmark.cpp +++ b/samples/today/benchmark.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -43,7 +44,7 @@ void outputOverview( void outputSegment( std::string_view name, std::vector& durations) noexcept { - std::sort(durations.begin(), durations.end()); + std::ranges::sort(durations); const auto count = durations.size(); const auto total = diff --git a/src/ClientGenerator.cpp b/src/ClientGenerator.cpp index ad01d3a1..5b472775 100644 --- a/src/ClientGenerator.cpp +++ b/src/ClientGenerator.cpp @@ -1120,18 +1120,15 @@ response::Value Variable<)cpp" std::vector> sortedValues( enumValues.size()); - std::transform(enumValues.cbegin(), - enumValues.cend(), + std::ranges::transform(enumValues, sortedValues.begin(), [](const auto& value) noexcept { return std::make_pair(value->name(), SchemaLoader::getSafeCppName(value->name())); }); - std::sort(sortedValues.begin(), - sortedValues.end(), - [](const auto& lhs, const auto& rhs) noexcept { - return internal::shorter_or_less {}(lhs.first, rhs.first); - }); + std::ranges::sort(sortedValues, [](const auto& lhs, const auto& rhs) noexcept { + return internal::shorter_or_less {}(lhs.first, rhs.first); + }); bool firstValue = true; diff --git a/src/GeneratorUtil.cpp b/src/GeneratorUtil.cpp index 8e3acaaf..131370c9 100644 --- a/src/GeneratorUtil.cpp +++ b/src/GeneratorUtil.cpp @@ -4,6 +4,7 @@ #include "GeneratorUtil.h" #include +#include namespace graphql::generator { @@ -12,17 +13,14 @@ IncludeGuardScope::IncludeGuardScope( : _outputFile(outputFile) , _includeGuardName(headerFileName.size(), char {}) { - std::transform(headerFileName.begin(), - headerFileName.end(), - _includeGuardName.begin(), - [](char ch) noexcept -> char { - if (ch == '.') - { - return '_'; - } - - return static_cast(std::toupper(ch)); - }); + std::ranges::transform(headerFileName, _includeGuardName.begin(), [](char ch) noexcept -> char { + if (ch == '.') + { + return '_'; + } + + return static_cast(std::toupper(ch)); + }); _outputFile << R"cpp(// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. diff --git a/src/GraphQLClient.cpp b/src/GraphQLClient.cpp index f56b0a24..b146f018 100644 --- a/src/GraphQLClient.cpp +++ b/src/GraphQLClient.cpp @@ -92,8 +92,7 @@ Error parseServiceError(response::Value&& error) auto locations = member.second.release(); result.locations.reserve(locations.size()); - std::transform(locations.begin(), - locations.end(), + std::ranges::transform(locations, std::back_inserter(result.locations), [](response::Value& location) { return parseServiceErrorLocation(std::move(location)); @@ -110,8 +109,7 @@ Error parseServiceError(response::Value&& error) auto segments = member.second.release(); result.path.reserve(segments.size()); - std::transform(segments.begin(), - segments.end(), + std::ranges::transform(segments, std::back_inserter(result.path), [](response::Value& segment) { return parseServiceErrorPathSegment(std::move(segment)); @@ -150,8 +148,7 @@ ServiceResponse parseServiceResponse(response::Value response) auto errors = member.second.release(); result.errors.reserve(errors.size()); - std::transform(errors.begin(), - errors.end(), + std::ranges::transform(errors, std::back_inserter(result.errors), [](response::Value& error) { return parseServiceError(std::move(error)); diff --git a/src/GraphQLResponse.cpp b/src/GraphQLResponse.cpp index 25b4ba56..d04a3bf3 100644 --- a/src/GraphQLResponse.cpp +++ b/src/GraphQLResponse.cpp @@ -100,9 +100,9 @@ bool IdType::operator==(const IdType& rhs) const noexcept return (std::holds_alternative(_data) ? internal::Base64::compareBase64(std::get(_data), - std::get(rhs._data)) + std::get(rhs._data)) : internal::Base64::compareBase64(std::get(rhs._data), - std::get(_data))) + std::get(_data))) == internal::Base64::Comparison::EqualTo; } @@ -145,7 +145,7 @@ bool IdType::operator<(const IdType& rhs) const noexcept return (std::holds_alternative(_data) ? (internal::Base64::compareBase64(std::get(_data), std::get(rhs._data)) - < internal::Base64::Comparison::EqualTo) + < internal::Base64::Comparison::EqualTo) : (internal::Base64::compareBase64(std::get(rhs._data), std::get(_data))) > internal::Base64::Comparison::EqualTo); @@ -1338,8 +1338,7 @@ bool Value::emplace_back(std::string&& name, Value&& value) } auto& mapData = std::get(_data); - const auto [itr, itrEnd] = std::equal_range(mapData.members.cbegin(), - mapData.members.cend(), + const auto [itr, itrEnd] = std::ranges::equal_range(mapData.members, std::nullopt, [&mapData, &name](std::optional lhs, std::optional rhs) noexcept { std::string_view lhsName { lhs == std::nullopt ? name : mapData.map[*lhs].first }; @@ -1368,8 +1367,7 @@ MapType::const_iterator Value::find(std::string_view name) const } const auto& mapData = std::get(typeData); - const auto [itr, itrEnd] = std::equal_range(mapData.members.cbegin(), - mapData.members.cend(), + const auto [itr, itrEnd] = std::ranges::equal_range(mapData.members, std::nullopt, [&mapData, name](std::optional lhs, std::optional rhs) noexcept { std::string_view lhsName { lhs == std::nullopt ? name : mapData.map[*lhs].first }; diff --git a/src/GraphQLService.cpp b/src/GraphQLService.cpp index af87a2c3..39b74479 100644 --- a/src/GraphQLService.cpp +++ b/src/GraphQLService.cpp @@ -86,8 +86,7 @@ error_path buildErrorPath(const std::optional& path) } result.reserve(segments.size()); - std::transform(segments.cbegin(), - segments.cend(), + std::ranges::transform(segments, std::back_inserter(result), [](const auto& segment) noexcept { return segment.get(); @@ -133,12 +132,9 @@ std::list schema_exception::convertMessages( { std::list errors; - std::transform(messages.begin(), - messages.end(), - std::back_inserter(errors), - [](std::string& message) noexcept { - return schema_error { std::move(message) }; - }); + std::ranges::transform(messages, std::back_inserter(errors), [](std::string& message) noexcept { + return schema_error { std::move(message) }; + }); return errors; } @@ -254,7 +250,7 @@ void await_worker_queue::resumePending() // Default to immediate synchronous execution. await_async::await_async() : _pimpl { std::static_pointer_cast( - std::make_shared>(std::make_shared())) } + std::make_shared>(std::make_shared())) } { } @@ -262,9 +258,9 @@ await_async::await_async() await_async::await_async(std::launch launch) : _pimpl { ((launch & std::launch::async) == std::launch::async) ? std::static_pointer_cast(std::make_shared>( - std::make_shared())) + std::make_shared())) : std::static_pointer_cast(std::make_shared>( - std::make_shared())) } + std::make_shared())) } { } @@ -1287,7 +1283,7 @@ AwaitableResolver Object::resolve(const SelectionSetParams& selectionSetParams, if (!errors.empty()) { - std::copy(errors.begin(), errors.end(), std::back_inserter(document.errors)); + std::ranges::copy(errors, std::back_inserter(document.errors)); } document.data.emplace_back(std::string { child.name }, {}); @@ -2170,8 +2166,7 @@ std::vector> Request::collectRegistratio { // Return all of the registered subscriptions for this field. registrations.reserve(itrListeners->second.size()); - std::transform(itrListeners->second.begin(), - itrListeners->second.end(), + std::ranges::transform(itrListeners->second, std::back_inserter(registrations), [this](const auto& key) noexcept { const auto itr = _subscriptions.find(key); diff --git a/src/Introspection.cpp b/src/Introspection.cpp index 5ac539e9..06bfb9cd 100644 --- a/src/Introspection.cpp +++ b/src/Introspection.cpp @@ -31,7 +31,7 @@ std::vector> Schema::getTypes() const const auto& types = _schema->types(); std::vector> result(types.size()); - std::transform(types.begin(), types.end(), result.begin(), [](const auto& entry) { + std::ranges::transform(types, result.begin(), [](const auto& entry) { return std::make_shared(std::make_shared(entry.second)); }); @@ -67,7 +67,7 @@ std::vector> Schema::getDirectives() const const auto& directives = _schema->directives(); std::vector> result(directives.size()); - std::transform(directives.begin(), directives.end(), result.begin(), [](const auto& entry) { + std::ranges::transform(directives, result.begin(), [](const auto& entry) { return std::make_shared(std::make_shared(entry)); }); @@ -141,7 +141,7 @@ std::optional>> Type::getInterfaces() const auto& interfaces = _type->interfaces(); auto result = std::make_optional>>(interfaces.size()); - std::transform(interfaces.begin(), interfaces.end(), result->begin(), [](const auto& entry) { + std::ranges::transform(interfaces, result->begin(), [](const auto& entry) { return std::make_shared(std::make_shared(entry)); }); @@ -164,16 +164,13 @@ std::optional>> Type::getPossibleTypes auto result = std::make_optional>>(possibleTypes.size()); - std::transform(possibleTypes.begin(), - possibleTypes.end(), - result->begin(), - [](const auto& entry) { - auto typeEntry = entry.lock(); + std::ranges::transform(possibleTypes, result->begin(), [](const auto& entry) { + auto typeEntry = entry.lock(); - return typeEntry && typeEntry->kind() == introspection::TypeKind::OBJECT - ? std::make_shared(std::make_shared(std::move(typeEntry))) - : std::shared_ptr {}; - }); + return typeEntry && typeEntry->kind() == introspection::TypeKind::OBJECT + ? std::make_shared(std::make_shared(std::move(typeEntry))) + : std::shared_ptr {}; + }); result->erase(std::remove(result->begin(), result->end(), std::shared_ptr {}), result->cend()); @@ -225,7 +222,7 @@ std::optional>> Type::getInputFi auto result = std::make_optional>>(inputFields.size()); - std::transform(inputFields.begin(), inputFields.end(), result->begin(), [](const auto& entry) { + std::ranges::transform(inputFields, result->begin(), [](const auto& entry) { return std::make_shared(std::make_shared(entry)); }); @@ -279,7 +276,7 @@ std::vector> Field::getArgs() const const auto& args = _field->args(); std::vector> result(args.size()); - std::transform(args.begin(), args.end(), result.begin(), [](const auto& entry) { + std::ranges::transform(args, result.begin(), [](const auto& entry) { return std::make_shared(std::make_shared(entry)); }); @@ -394,7 +391,7 @@ std::vector> Directive::getArgs() const const auto& args = _directive->args(); std::vector> result(args.size()); - std::transform(args.begin(), args.end(), result.begin(), [](const auto& entry) { + std::ranges::transform(args, result.begin(), [](const auto& entry) { return std::make_shared(std::make_shared(entry)); }); diff --git a/src/RequestLoader.cpp b/src/RequestLoader.cpp index 44d2a47b..2673c707 100644 --- a/src/RequestLoader.cpp +++ b/src/RequestLoader.cpp @@ -418,8 +418,7 @@ void RequestLoader::addTypesToSchema() { std::vector values(enumType.values.size()); - std::transform(enumType.values.cbegin(), - enumType.values.cend(), + std::ranges::transform(enumType.values, values.begin(), [](const EnumValueType& value) noexcept { return schema::EnumValueType { @@ -441,8 +440,7 @@ void RequestLoader::addTypesToSchema() { std::vector> fields(inputType.fields.size()); - std::transform(inputType.fields.cbegin(), - inputType.fields.cend(), + std::ranges::transform(inputType.fields, fields.begin(), [this](const InputField& field) noexcept { return schema::InputValue::Make(field.name, @@ -463,8 +461,7 @@ void RequestLoader::addTypesToSchema() { std::vector> options(unionType.options.size()); - std::transform(unionType.options.cbegin(), - unionType.options.cend(), + std::ranges::transform(unionType.options, options.begin(), [this](std::string_view option) noexcept { return _schema->LookupType(option); @@ -482,15 +479,13 @@ void RequestLoader::addTypesToSchema() { std::vector> fields(interfaceType.fields.size()); - std::transform(interfaceType.fields.cbegin(), - interfaceType.fields.cend(), + std::ranges::transform(interfaceType.fields, fields.begin(), [this](const OutputField& field) noexcept { std::vector> arguments( field.arguments.size()); - std::transform(field.arguments.cbegin(), - field.arguments.cend(), + std::ranges::transform(field.arguments, arguments.begin(), [this](const InputField& argument) noexcept { return schema::InputValue::Make(argument.name, @@ -519,8 +514,7 @@ void RequestLoader::addTypesToSchema() std::vector> interfaces( objectType.interfaces.size()); - std::transform(objectType.interfaces.cbegin(), - objectType.interfaces.cend(), + std::ranges::transform(objectType.interfaces, interfaces.begin(), [&interfaceTypes](std::string_view interfaceName) noexcept { return interfaceTypes[interfaceName]; @@ -533,15 +527,13 @@ void RequestLoader::addTypesToSchema() { std::vector> fields(objectType.fields.size()); - std::transform(objectType.fields.cbegin(), - objectType.fields.cend(), + std::ranges::transform(objectType.fields, fields.begin(), [this](const OutputField& field) noexcept { std::vector> arguments( field.arguments.size()); - std::transform(field.arguments.cbegin(), - field.arguments.cend(), + std::ranges::transform(field.arguments, arguments.begin(), [this](const InputField& argument) noexcept { return schema::InputValue::Make(argument.name, @@ -565,8 +557,7 @@ void RequestLoader::addTypesToSchema() { std::vector locations(directive.locations.size()); - std::transform(directive.locations.cbegin(), - directive.locations.cend(), + std::ranges::transform(directive.locations, locations.begin(), [](std::string_view locationName) noexcept { response::Value locationValue(response::Type::EnumValue); @@ -579,8 +570,7 @@ void RequestLoader::addTypesToSchema() std::vector> arguments( directive.arguments.size()); - std::transform(directive.arguments.cbegin(), - directive.arguments.cend(), + std::ranges::transform(directive.arguments, arguments.begin(), [this](const InputField& argument) noexcept { return schema::InputValue::Make(argument.name, @@ -624,11 +614,11 @@ RequestSchemaType RequestLoader::getSchemaType( { bool nonNull = true; - for (auto itr = modifiers.crbegin(); itr != modifiers.crend(); ++itr) + for (const auto modifier : std::views::all(modifiers) | std::views::reverse) { if (nonNull) { - switch (*itr) + switch (modifier) { case service::TypeModifier::None: case service::TypeModifier::List: @@ -643,7 +633,7 @@ RequestSchemaType RequestLoader::getSchemaType( } } - switch (*itr) + switch (modifier) { case service::TypeModifier::None: { @@ -911,29 +901,26 @@ void RequestLoader::reorderInputTypeDependencies(Operation& operation) } // Build the dependency list for each input type. - std::for_each(operation.referencedInputTypes.begin(), - operation.referencedInputTypes.end(), - [](RequestInputType& entry) noexcept { - const auto& fields = entry.type->inputFields(); - std::for_each(fields.begin(), - fields.end(), - [&entry](const std::shared_ptr& field) noexcept { - const auto [inputType, modifiers] = unwrapSchemaType(field->type().lock()); - - if (inputType->kind() == introspection::TypeKind::INPUT_OBJECT) + std::ranges::for_each(operation.referencedInputTypes, [](RequestInputType& entry) noexcept { + const auto& fields = entry.type->inputFields(); + std::ranges::for_each(fields, + [&entry](const std::shared_ptr& field) noexcept { + const auto [inputType, modifiers] = unwrapSchemaType(field->type().lock()); + + if (inputType->kind() == introspection::TypeKind::INPUT_OBJECT) + { + // https://spec.graphql.org/October2021/#sec-Input-Objects.Circular-References + if (!modifiers.empty() && modifiers.front() != service::TypeModifier::None) { - // https://spec.graphql.org/October2021/#sec-Input-Objects.Circular-References - if (!modifiers.empty() && modifiers.front() != service::TypeModifier::None) - { - entry.declarations.push_back(inputType->name()); - } - else - { - entry.dependencies.insert(inputType->name()); - } + entry.declarations.push_back(inputType->name()); } - }); - }); + else + { + entry.dependencies.insert(inputType->name()); + } + } + }); + }); std::unordered_set handled; auto itr = operation.referencedInputTypes.begin(); diff --git a/src/Schema.cpp b/src/Schema.cpp index 2e4ac1ba..b448089a 100644 --- a/src/Schema.cpp +++ b/src/Schema.cpp @@ -371,12 +371,9 @@ EnumType::EnumType(init&& params) void EnumType::AddEnumValues(std::vector&& enumValues) { _enumValues.resize(enumValues.size()); - std::transform(enumValues.begin(), - enumValues.end(), - _enumValues.begin(), - [](const auto& value) { - return EnumValue::Make(value.value, value.description, value.deprecationReason); - }); + std::ranges::transform(enumValues, _enumValues.begin(), [](const auto& value) { + return EnumValue::Make(value.value, value.description, value.deprecationReason); + }); } std::string_view EnumType::name() const noexcept diff --git a/src/SchemaGenerator.cpp b/src/SchemaGenerator.cpp index c6ef33df..d0d26f18 100644 --- a/src/SchemaGenerator.cpp +++ b/src/SchemaGenerator.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -243,17 +244,14 @@ static_assert(graphql::internal::MinorVersion == )cpp" std::vector> sortedValues( enumType.values.size()); - std::transform(enumType.values.cbegin(), - enumType.values.cend(), + std::ranges::transform(enumType.values, sortedValues.begin(), [](const auto& value) noexcept { return std::make_pair(value.value, value.cppValue); }); - std::sort(sortedValues.begin(), - sortedValues.end(), - [](const auto& lhs, const auto& rhs) noexcept { - return internal::shorter_or_less {}(lhs.first, rhs.first); - }); + std::ranges::sort(sortedValues, [](const auto& lhs, const auto& rhs) noexcept { + return internal::shorter_or_less {}(lhs.first, rhs.first); + }); firstValue = true; @@ -2518,8 +2516,7 @@ service::ResolverMap )cpp" std::map resolvers; - std::transform(objectType.fields.cbegin(), - objectType.fields.cend(), + std::ranges::transform(objectType.fields, std::inserter(resolvers, resolvers.begin()), [](const OutputField& outputField) noexcept { const auto resolverName = SchemaLoader::getOutputCppResolver(outputField); diff --git a/src/SchemaLoader.cpp b/src/SchemaLoader.cpp index 3e0827a8..e6c4be43 100644 --- a/src/SchemaLoader.cpp +++ b/src/SchemaLoader.cpp @@ -379,24 +379,22 @@ void SchemaLoader::fixupInputFieldList(InputFieldList& fields) void SchemaLoader::reorderInputTypeDependencies() { // Build the dependency list for each input type. - std::for_each(_inputTypes.begin(), _inputTypes.end(), [](InputType& entry) noexcept { - std::for_each(entry.fields.cbegin(), - entry.fields.cend(), - [&entry](const InputField& field) noexcept { - if (field.fieldType == InputFieldType::Input) + std::ranges::for_each(_inputTypes, [](InputType& entry) noexcept { + std::ranges::for_each(entry.fields, [&entry](const InputField& field) noexcept { + if (field.fieldType == InputFieldType::Input) + { + // https://spec.graphql.org/October2021/#sec-Input-Objects.Circular-References + if (!field.modifiers.empty() + && field.modifiers.front() != service::TypeModifier::None) { - // https://spec.graphql.org/October2021/#sec-Input-Objects.Circular-References - if (!field.modifiers.empty() - && field.modifiers.front() != service::TypeModifier::None) - { - entry.declarations.push_back(field.type); - } - else - { - entry.dependencies.insert(field.type); - } + entry.declarations.push_back(field.type); } - }); + else + { + entry.dependencies.insert(field.type); + } + } + }); }); std::unordered_set handled; diff --git a/src/Validation.cpp b/src/Validation.cpp index 9ed417e1..65204d9e 100644 --- a/src/Validation.cpp +++ b/src/Validation.cpp @@ -575,8 +575,7 @@ void ValidateExecutableVisitor::visit(const peg::ast_node& root) unreferencedFragments.erase(name); } - std::transform(unreferencedFragments.begin(), - unreferencedFragments.end(), + std::ranges::transform(unreferencedFragments, std::back_inserter(_errors), [](const auto& fragmentDefinition) noexcept { auto position = fragmentDefinition.second.get().begin(); diff --git a/test/ResponseTests.cpp b/test/ResponseTests.cpp index 4327186f..9da7d6a0 100644 --- a/test/ResponseTests.cpp +++ b/test/ResponseTests.cpp @@ -5,6 +5,8 @@ #include "graphqlservice/GraphQLResponse.h" +#include + using namespace graphql; TEST(ResponseCase, ValueConstructorFromStringLiteral) @@ -22,7 +24,7 @@ TEST(ResponseCase, IdTypeCompareEqual) std::string_view fakeIdString { "fakeId" }; response::IdType result(fakeIdString.size()); - std::copy(fakeIdString.cbegin(), fakeIdString.cend(), result.begin()); + std::ranges::copy(fakeIdString, result.begin()); return response::IdType { std::move(result) }; }(); From e8d8a856a9128cbf2dd4f7f407b0e97464006773 Mon Sep 17 00:00:00 2001 From: Bill Avery Date: Mon, 16 Sep 2024 17:55:48 -0700 Subject: [PATCH 4/5] feat(format): replace trivial uses of std::ostringstream with std::format --- include/graphqlservice/GraphQLService.h | 24 +- samples/client/benchmark/BenchmarkClient.cpp | 1 - .../client/multiple/MultipleQueriesClient.cpp | 1 - samples/client/mutate/MutateClient.cpp | 1 - .../client/nestedinput/NestedInputClient.cpp | 1 - samples/client/query/QueryClient.cpp | 1 - samples/client/subscribe/SubscribeClient.cpp | 1 - samples/learn/schema/DroidObject.cpp | 1 - samples/learn/schema/HumanObject.cpp | 1 - samples/learn/schema/MutationObject.cpp | 1 - samples/learn/schema/QueryObject.cpp | 1 - samples/learn/schema/ReviewObject.cpp | 1 - samples/learn/schema/StarWarsSchema.cpp | 1 - samples/proxy/query/ProxyClient.cpp | 1 - samples/proxy/schema/ProxySchema.cpp | 1 - samples/proxy/schema/QueryObject.cpp | 1 - samples/today/TodayMock.cpp | 13 +- .../AppointmentConnectionObject.cpp | 1 - .../nointrospection/AppointmentEdgeObject.cpp | 1 - .../nointrospection/AppointmentObject.cpp | 1 - .../CompleteTaskPayloadObject.cpp | 1 - .../today/nointrospection/ExpensiveObject.cpp | 1 - .../FolderConnectionObject.cpp | 1 - .../nointrospection/FolderEdgeObject.cpp | 1 - .../today/nointrospection/FolderObject.cpp | 1 - .../today/nointrospection/MutationObject.cpp | 1 - .../nointrospection/NestedTypeObject.cpp | 1 - .../today/nointrospection/PageInfoObject.cpp | 1 - samples/today/nointrospection/QueryObject.cpp | 1 - .../nointrospection/SubscriptionObject.cpp | 1 - .../nointrospection/TaskConnectionObject.cpp | 1 - .../today/nointrospection/TaskEdgeObject.cpp | 1 - samples/today/nointrospection/TaskObject.cpp | 1 - samples/today/nointrospection/TodaySchema.cpp | 1 - .../schema/AppointmentConnectionObject.cpp | 1 - .../today/schema/AppointmentEdgeObject.cpp | 1 - samples/today/schema/AppointmentObject.cpp | 1 - .../schema/CompleteTaskPayloadObject.cpp | 1 - samples/today/schema/ExpensiveObject.cpp | 1 - .../today/schema/FolderConnectionObject.cpp | 1 - samples/today/schema/FolderEdgeObject.cpp | 1 - samples/today/schema/FolderObject.cpp | 1 - samples/today/schema/MutationObject.cpp | 1 - samples/today/schema/NestedTypeObject.cpp | 1 - samples/today/schema/PageInfoObject.cpp | 1 - samples/today/schema/QueryObject.cpp | 1 - samples/today/schema/SubscriptionObject.cpp | 1 - samples/today/schema/TaskConnectionObject.cpp | 1 - samples/today/schema/TaskEdgeObject.cpp | 1 - samples/today/schema/TaskObject.cpp | 1 - samples/today/schema/TodaySchema.cpp | 1 - samples/validation/schema/AlienObject.cpp | 1 - samples/validation/schema/ArgumentsObject.cpp | 1 - samples/validation/schema/CatObject.cpp | 1 - samples/validation/schema/DogObject.cpp | 1 - samples/validation/schema/HumanObject.cpp | 1 - samples/validation/schema/MessageObject.cpp | 1 - .../schema/MutateDogResultObject.cpp | 1 - samples/validation/schema/MutationObject.cpp | 1 - samples/validation/schema/QueryObject.cpp | 1 - .../validation/schema/SubscriptionObject.cpp | 1 - .../validation/schema/ValidationSchema.cpp | 1 - src/ClientGenerator.cpp | 36 +- src/GeneratorLoader.cpp | 10 +- src/GraphQLService.cpp | 124 ++--- src/RequestLoader.cpp | 35 +- src/SchemaGenerator.cpp | 60 +-- src/SchemaLoader.cpp | 161 +++--- src/SyntaxTree.cpp | 13 +- src/Validation.cpp | 457 ++++++++---------- src/introspection/DirectiveObject.cpp | 1 - src/introspection/EnumValueObject.cpp | 1 - src/introspection/FieldObject.cpp | 1 - src/introspection/InputValueObject.cpp | 1 - src/introspection/IntrospectionSchema.cpp | 1 - src/introspection/SchemaObject.cpp | 1 - src/introspection/TypeObject.cpp | 1 - 77 files changed, 388 insertions(+), 612 deletions(-) diff --git a/include/graphqlservice/GraphQLService.h b/include/graphqlservice/GraphQLService.h index b6c84687..1474e91a 100644 --- a/include/graphqlservice/GraphQLService.h +++ b/include/graphqlservice/GraphQLService.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -23,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -686,11 +686,7 @@ struct ModifiedArgument for (auto& error : errors) { - std::ostringstream message; - - message << "Invalid argument: " << name << " error: " << error.message; - - error.message = message.str(); + error.message = std::format("Invalid argument: {} error: {}", name, error.message); } throw schema_exception(std::move(errors)); @@ -1201,12 +1197,11 @@ struct ModifiedResult } catch (const std::exception& ex) { - std::ostringstream message; + auto message = std::format("Field error name: {} unknown error: {}", + params.fieldName, + ex.what()); - message << "Field error name: " << params.fieldName - << " unknown error: " << ex.what(); - - document.errors.emplace_back(schema_error { message.str(), + document.errors.emplace_back(schema_error { std::move(message), params.getLocation(), buildErrorPath(params.errorPath) }); } @@ -1294,11 +1289,10 @@ struct ModifiedResult } catch (const std::exception& ex) { - std::ostringstream message; - - message << "Field name: " << params.fieldName << " unknown error: " << ex.what(); + auto message = + std::format("Field name: {} unknown error: {}", params.fieldName, ex.what()); - document.errors.emplace_back(schema_error { message.str(), + document.errors.emplace_back(schema_error { std::move(message), params.getLocation(), buildErrorPath(params.errorPath) }); } diff --git a/samples/client/benchmark/BenchmarkClient.cpp b/samples/client/benchmark/BenchmarkClient.cpp index 4ce3e7d6..5a7e346b 100644 --- a/samples/client/benchmark/BenchmarkClient.cpp +++ b/samples/client/benchmark/BenchmarkClient.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/samples/client/multiple/MultipleQueriesClient.cpp b/samples/client/multiple/MultipleQueriesClient.cpp index 5383da2f..3b5d533f 100644 --- a/samples/client/multiple/MultipleQueriesClient.cpp +++ b/samples/client/multiple/MultipleQueriesClient.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/samples/client/mutate/MutateClient.cpp b/samples/client/mutate/MutateClient.cpp index 019f2f43..8db8bd6a 100644 --- a/samples/client/mutate/MutateClient.cpp +++ b/samples/client/mutate/MutateClient.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/samples/client/nestedinput/NestedInputClient.cpp b/samples/client/nestedinput/NestedInputClient.cpp index 16708663..8de48529 100644 --- a/samples/client/nestedinput/NestedInputClient.cpp +++ b/samples/client/nestedinput/NestedInputClient.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/samples/client/query/QueryClient.cpp b/samples/client/query/QueryClient.cpp index 61422c40..0e874d20 100644 --- a/samples/client/query/QueryClient.cpp +++ b/samples/client/query/QueryClient.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/samples/client/subscribe/SubscribeClient.cpp b/samples/client/subscribe/SubscribeClient.cpp index cf76839b..ea516d6c 100644 --- a/samples/client/subscribe/SubscribeClient.cpp +++ b/samples/client/subscribe/SubscribeClient.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/samples/learn/schema/DroidObject.cpp b/samples/learn/schema/DroidObject.cpp index 6f9a706f..16473f96 100644 --- a/samples/learn/schema/DroidObject.cpp +++ b/samples/learn/schema/DroidObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/learn/schema/HumanObject.cpp b/samples/learn/schema/HumanObject.cpp index 1094ed45..ab8ad2ed 100644 --- a/samples/learn/schema/HumanObject.cpp +++ b/samples/learn/schema/HumanObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/learn/schema/MutationObject.cpp b/samples/learn/schema/MutationObject.cpp index 9bdb2b5f..ef6dcbb1 100644 --- a/samples/learn/schema/MutationObject.cpp +++ b/samples/learn/schema/MutationObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/learn/schema/QueryObject.cpp b/samples/learn/schema/QueryObject.cpp index bc1cf10f..061d89aa 100644 --- a/samples/learn/schema/QueryObject.cpp +++ b/samples/learn/schema/QueryObject.cpp @@ -15,7 +15,6 @@ #include #include -#include #include #include diff --git a/samples/learn/schema/ReviewObject.cpp b/samples/learn/schema/ReviewObject.cpp index ebe1c4b9..240ed953 100644 --- a/samples/learn/schema/ReviewObject.cpp +++ b/samples/learn/schema/ReviewObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/learn/schema/StarWarsSchema.cpp b/samples/learn/schema/StarWarsSchema.cpp index a5d8e9e2..5288f5d8 100644 --- a/samples/learn/schema/StarWarsSchema.cpp +++ b/samples/learn/schema/StarWarsSchema.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff --git a/samples/proxy/query/ProxyClient.cpp b/samples/proxy/query/ProxyClient.cpp index 04b6546c..6124a0ac 100644 --- a/samples/proxy/query/ProxyClient.cpp +++ b/samples/proxy/query/ProxyClient.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/samples/proxy/schema/ProxySchema.cpp b/samples/proxy/schema/ProxySchema.cpp index e38783ba..0a6dc2f9 100644 --- a/samples/proxy/schema/ProxySchema.cpp +++ b/samples/proxy/schema/ProxySchema.cpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include diff --git a/samples/proxy/schema/QueryObject.cpp b/samples/proxy/schema/QueryObject.cpp index f8989a70..b07fe96c 100644 --- a/samples/proxy/schema/QueryObject.cpp +++ b/samples/proxy/schema/QueryObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/today/TodayMock.cpp b/samples/today/TodayMock.cpp index d7464511..4d808469 100644 --- a/samples/today/TodayMock.cpp +++ b/samples/today/TodayMock.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -569,10 +570,8 @@ struct EdgeConstraints { if (*first < 0) { - std::ostringstream error; - - error << "Invalid argument: first value: " << *first; - throw service::schema_exception { { service::schema_error { error.str() } } }; + auto error = std::format("Invalid argument: first value: {}", *first); + throw service::schema_exception { { service::schema_error { std::move(error) } } }; } if (itrLast - itrFirst > *first) @@ -585,10 +584,8 @@ struct EdgeConstraints { if (*last < 0) { - std::ostringstream error; - - error << "Invalid argument: last value: " << *last; - throw service::schema_exception { { service::schema_error { error.str() } } }; + auto error = std::format("Invalid argument: last value: {}", *last); + throw service::schema_exception { { service::schema_error { std::move(error) } } }; } if (itrLast - itrFirst > *last) diff --git a/samples/today/nointrospection/AppointmentConnectionObject.cpp b/samples/today/nointrospection/AppointmentConnectionObject.cpp index d0fe0178..9ea706b8 100644 --- a/samples/today/nointrospection/AppointmentConnectionObject.cpp +++ b/samples/today/nointrospection/AppointmentConnectionObject.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/AppointmentEdgeObject.cpp b/samples/today/nointrospection/AppointmentEdgeObject.cpp index f599fdf2..b79f8a66 100644 --- a/samples/today/nointrospection/AppointmentEdgeObject.cpp +++ b/samples/today/nointrospection/AppointmentEdgeObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/AppointmentObject.cpp b/samples/today/nointrospection/AppointmentObject.cpp index 63062308..4ff77df9 100644 --- a/samples/today/nointrospection/AppointmentObject.cpp +++ b/samples/today/nointrospection/AppointmentObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/CompleteTaskPayloadObject.cpp b/samples/today/nointrospection/CompleteTaskPayloadObject.cpp index 0e0e08b0..584a011d 100644 --- a/samples/today/nointrospection/CompleteTaskPayloadObject.cpp +++ b/samples/today/nointrospection/CompleteTaskPayloadObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/ExpensiveObject.cpp b/samples/today/nointrospection/ExpensiveObject.cpp index 4583f271..6c984f82 100644 --- a/samples/today/nointrospection/ExpensiveObject.cpp +++ b/samples/today/nointrospection/ExpensiveObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/FolderConnectionObject.cpp b/samples/today/nointrospection/FolderConnectionObject.cpp index 75a588a3..78fd9094 100644 --- a/samples/today/nointrospection/FolderConnectionObject.cpp +++ b/samples/today/nointrospection/FolderConnectionObject.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/FolderEdgeObject.cpp b/samples/today/nointrospection/FolderEdgeObject.cpp index 203c1aa2..179e4c37 100644 --- a/samples/today/nointrospection/FolderEdgeObject.cpp +++ b/samples/today/nointrospection/FolderEdgeObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/FolderObject.cpp b/samples/today/nointrospection/FolderObject.cpp index 9f0b44e5..2fc07efd 100644 --- a/samples/today/nointrospection/FolderObject.cpp +++ b/samples/today/nointrospection/FolderObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/MutationObject.cpp b/samples/today/nointrospection/MutationObject.cpp index 4482e672..dd7228d1 100644 --- a/samples/today/nointrospection/MutationObject.cpp +++ b/samples/today/nointrospection/MutationObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/NestedTypeObject.cpp b/samples/today/nointrospection/NestedTypeObject.cpp index 0298ed0a..f85ca02c 100644 --- a/samples/today/nointrospection/NestedTypeObject.cpp +++ b/samples/today/nointrospection/NestedTypeObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/PageInfoObject.cpp b/samples/today/nointrospection/PageInfoObject.cpp index c356dbac..15021499 100644 --- a/samples/today/nointrospection/PageInfoObject.cpp +++ b/samples/today/nointrospection/PageInfoObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/QueryObject.cpp b/samples/today/nointrospection/QueryObject.cpp index e624f909..f87d63d6 100644 --- a/samples/today/nointrospection/QueryObject.cpp +++ b/samples/today/nointrospection/QueryObject.cpp @@ -21,7 +21,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/SubscriptionObject.cpp b/samples/today/nointrospection/SubscriptionObject.cpp index 104e9fe0..16a729fc 100644 --- a/samples/today/nointrospection/SubscriptionObject.cpp +++ b/samples/today/nointrospection/SubscriptionObject.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/TaskConnectionObject.cpp b/samples/today/nointrospection/TaskConnectionObject.cpp index a49a51ac..0950ae4c 100644 --- a/samples/today/nointrospection/TaskConnectionObject.cpp +++ b/samples/today/nointrospection/TaskConnectionObject.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/TaskEdgeObject.cpp b/samples/today/nointrospection/TaskEdgeObject.cpp index 300a0737..d48b9bad 100644 --- a/samples/today/nointrospection/TaskEdgeObject.cpp +++ b/samples/today/nointrospection/TaskEdgeObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/TaskObject.cpp b/samples/today/nointrospection/TaskObject.cpp index cd58aa7a..8ce3d664 100644 --- a/samples/today/nointrospection/TaskObject.cpp +++ b/samples/today/nointrospection/TaskObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/today/nointrospection/TodaySchema.cpp b/samples/today/nointrospection/TodaySchema.cpp index 4dd8886a..cb72d659 100644 --- a/samples/today/nointrospection/TodaySchema.cpp +++ b/samples/today/nointrospection/TodaySchema.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include diff --git a/samples/today/schema/AppointmentConnectionObject.cpp b/samples/today/schema/AppointmentConnectionObject.cpp index d0fe0178..9ea706b8 100644 --- a/samples/today/schema/AppointmentConnectionObject.cpp +++ b/samples/today/schema/AppointmentConnectionObject.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/AppointmentEdgeObject.cpp b/samples/today/schema/AppointmentEdgeObject.cpp index f599fdf2..b79f8a66 100644 --- a/samples/today/schema/AppointmentEdgeObject.cpp +++ b/samples/today/schema/AppointmentEdgeObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/AppointmentObject.cpp b/samples/today/schema/AppointmentObject.cpp index 63062308..4ff77df9 100644 --- a/samples/today/schema/AppointmentObject.cpp +++ b/samples/today/schema/AppointmentObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/CompleteTaskPayloadObject.cpp b/samples/today/schema/CompleteTaskPayloadObject.cpp index 0e0e08b0..584a011d 100644 --- a/samples/today/schema/CompleteTaskPayloadObject.cpp +++ b/samples/today/schema/CompleteTaskPayloadObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/ExpensiveObject.cpp b/samples/today/schema/ExpensiveObject.cpp index 4583f271..6c984f82 100644 --- a/samples/today/schema/ExpensiveObject.cpp +++ b/samples/today/schema/ExpensiveObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/FolderConnectionObject.cpp b/samples/today/schema/FolderConnectionObject.cpp index 75a588a3..78fd9094 100644 --- a/samples/today/schema/FolderConnectionObject.cpp +++ b/samples/today/schema/FolderConnectionObject.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/FolderEdgeObject.cpp b/samples/today/schema/FolderEdgeObject.cpp index 203c1aa2..179e4c37 100644 --- a/samples/today/schema/FolderEdgeObject.cpp +++ b/samples/today/schema/FolderEdgeObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/FolderObject.cpp b/samples/today/schema/FolderObject.cpp index 9f0b44e5..2fc07efd 100644 --- a/samples/today/schema/FolderObject.cpp +++ b/samples/today/schema/FolderObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/MutationObject.cpp b/samples/today/schema/MutationObject.cpp index 4482e672..dd7228d1 100644 --- a/samples/today/schema/MutationObject.cpp +++ b/samples/today/schema/MutationObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/NestedTypeObject.cpp b/samples/today/schema/NestedTypeObject.cpp index bd9c90d1..fc772276 100644 --- a/samples/today/schema/NestedTypeObject.cpp +++ b/samples/today/schema/NestedTypeObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/PageInfoObject.cpp b/samples/today/schema/PageInfoObject.cpp index c356dbac..15021499 100644 --- a/samples/today/schema/PageInfoObject.cpp +++ b/samples/today/schema/PageInfoObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/QueryObject.cpp b/samples/today/schema/QueryObject.cpp index ac999274..953af738 100644 --- a/samples/today/schema/QueryObject.cpp +++ b/samples/today/schema/QueryObject.cpp @@ -22,7 +22,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/SubscriptionObject.cpp b/samples/today/schema/SubscriptionObject.cpp index 104e9fe0..16a729fc 100644 --- a/samples/today/schema/SubscriptionObject.cpp +++ b/samples/today/schema/SubscriptionObject.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/TaskConnectionObject.cpp b/samples/today/schema/TaskConnectionObject.cpp index a49a51ac..0950ae4c 100644 --- a/samples/today/schema/TaskConnectionObject.cpp +++ b/samples/today/schema/TaskConnectionObject.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/TaskEdgeObject.cpp b/samples/today/schema/TaskEdgeObject.cpp index 300a0737..d48b9bad 100644 --- a/samples/today/schema/TaskEdgeObject.cpp +++ b/samples/today/schema/TaskEdgeObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/TaskObject.cpp b/samples/today/schema/TaskObject.cpp index cd58aa7a..8ce3d664 100644 --- a/samples/today/schema/TaskObject.cpp +++ b/samples/today/schema/TaskObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/today/schema/TodaySchema.cpp b/samples/today/schema/TodaySchema.cpp index 27cd44ce..f55a0831 100644 --- a/samples/today/schema/TodaySchema.cpp +++ b/samples/today/schema/TodaySchema.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include diff --git a/samples/validation/schema/AlienObject.cpp b/samples/validation/schema/AlienObject.cpp index 0687dff9..b6c0d4be 100644 --- a/samples/validation/schema/AlienObject.cpp +++ b/samples/validation/schema/AlienObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/validation/schema/ArgumentsObject.cpp b/samples/validation/schema/ArgumentsObject.cpp index 80a06987..0a180be7 100644 --- a/samples/validation/schema/ArgumentsObject.cpp +++ b/samples/validation/schema/ArgumentsObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/validation/schema/CatObject.cpp b/samples/validation/schema/CatObject.cpp index 35dcb20a..30df47f5 100644 --- a/samples/validation/schema/CatObject.cpp +++ b/samples/validation/schema/CatObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/validation/schema/DogObject.cpp b/samples/validation/schema/DogObject.cpp index e6785b43..6e5aeb7b 100644 --- a/samples/validation/schema/DogObject.cpp +++ b/samples/validation/schema/DogObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/validation/schema/HumanObject.cpp b/samples/validation/schema/HumanObject.cpp index 7294ffd2..6b0450a1 100644 --- a/samples/validation/schema/HumanObject.cpp +++ b/samples/validation/schema/HumanObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/validation/schema/MessageObject.cpp b/samples/validation/schema/MessageObject.cpp index 5897962e..df48b7f7 100644 --- a/samples/validation/schema/MessageObject.cpp +++ b/samples/validation/schema/MessageObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/validation/schema/MutateDogResultObject.cpp b/samples/validation/schema/MutateDogResultObject.cpp index 7ca813a2..ab872c93 100644 --- a/samples/validation/schema/MutateDogResultObject.cpp +++ b/samples/validation/schema/MutateDogResultObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/samples/validation/schema/MutationObject.cpp b/samples/validation/schema/MutationObject.cpp index 1ec98fb1..6a1fc565 100644 --- a/samples/validation/schema/MutationObject.cpp +++ b/samples/validation/schema/MutationObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/validation/schema/QueryObject.cpp b/samples/validation/schema/QueryObject.cpp index 2bf27de3..c15a5f0b 100644 --- a/samples/validation/schema/QueryObject.cpp +++ b/samples/validation/schema/QueryObject.cpp @@ -17,7 +17,6 @@ #include #include -#include #include #include diff --git a/samples/validation/schema/SubscriptionObject.cpp b/samples/validation/schema/SubscriptionObject.cpp index 694693b8..e0437189 100644 --- a/samples/validation/schema/SubscriptionObject.cpp +++ b/samples/validation/schema/SubscriptionObject.cpp @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/samples/validation/schema/ValidationSchema.cpp b/samples/validation/schema/ValidationSchema.cpp index 40410c97..bc7c42b8 100644 --- a/samples/validation/schema/ValidationSchema.cpp +++ b/samples/validation/schema/ValidationSchema.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include diff --git a/src/ClientGenerator.cpp b/src/ClientGenerator.cpp index 5b472775..8af33dff 100644 --- a/src/ClientGenerator.cpp +++ b/src/ClientGenerator.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -113,12 +114,11 @@ const std::string& Generator::getOperationNamespace(const Operation& operation) for (const auto& entry : operations) { - std::ostringstream oss; + auto value = std::format(R"cpp({}::{})cpp", + _requestLoader.getOperationType(entry), + _requestLoader.getOperationNamespace(entry)); - oss << _requestLoader.getOperationType(entry) << R"cpp(::)cpp" - << _requestLoader.getOperationNamespace(entry); - - result.emplace(entry.name, oss.str()); + result.emplace(entry.name, std::move(value)); } return result; @@ -138,15 +138,17 @@ std::string Generator::getResponseFieldCppType( case introspection::TypeKind::INTERFACE: case introspection::TypeKind::UNION: { - std::ostringstream oss; + std::string prefix; if (!currentScope.empty()) { - oss << currentScope << R"cpp(::)cpp"; + prefix = std::format(R"cpp({}::)cpp", currentScope); } - oss << responseField.cppName << R"cpp(_)cpp" << responseField.type->name(); - result = SchemaLoader::getSafeCppName(oss.str()); + result = SchemaLoader::getSafeCppName(std::format(R"cpp({}{}_{})cpp", + prefix, + responseField.cppName, + responseField.type->name())); break; } @@ -619,7 +621,6 @@ bool Generator::outputResponseFieldType(std::ostream& headerFile, bool Generator::outputModule() const noexcept { std::ofstream moduleFile(_modulePath, std::ios_base::trunc); - std::ostringstream ossNamespace; moduleFile << R"cpp(// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. @@ -810,7 +811,6 @@ bool Generator::outputSource() const noexcept #include #include #include -#include #include #include #include @@ -1167,11 +1167,8 @@ response::Value Variable<)cpp" pendingSeparator.add(); } - std::ostringstream oss; - - oss << getOperationNamespace(operation) << R"cpp(::Response)cpp"; - - const auto currentScope = oss.str(); + const auto currentScope = + std::format(R"cpp({}::Response)cpp", getOperationNamespace(operation)); const auto& responseType = _requestLoader.getResponseType(operation); for (const auto& responseField : responseType.fields) @@ -1350,11 +1347,8 @@ const std::string& GetOperationName() noexcept bool Generator::outputModifiedResponseImplementation(std::ostream& sourceFile, const std::string& outerScope, const ResponseField& responseField) const noexcept { - std::ostringstream oss; - - oss << outerScope << R"cpp(::)cpp" << getResponseFieldCppType(responseField); - - const auto cppType = oss.str(); + const auto cppType = + std::format(R"cpp({}::{})cpp", outerScope, getResponseFieldCppType(responseField)); std::unordered_set fieldNames; switch (responseField.type->kind()) diff --git a/src/GeneratorLoader.cpp b/src/GeneratorLoader.cpp index c57ed8fe..38c3c29a 100644 --- a/src/GeneratorLoader.cpp +++ b/src/GeneratorLoader.cpp @@ -6,6 +6,7 @@ #include "graphqlservice/internal/Grammar.h" #include +#include namespace graphql::generator { @@ -96,13 +97,12 @@ void DefaultValueVisitor::visit(const peg::ast_node& value) } else if (value.is_type()) { - std::ostringstream error; const auto position = value.begin(); + const auto error = std::format("Unexpected variable in default value line: {} column: {}", + position.line, + position.column); - error << "Unexpected variable in default value line: " << position.line - << " column: " << position.column; - - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } } diff --git a/src/GraphQLService.cpp b/src/GraphQLService.cpp index 39b74479..ab84142a 100644 --- a/src/GraphQLService.cpp +++ b/src/GraphQLService.cpp @@ -170,13 +170,7 @@ unimplemented_method::unimplemented_method(std::string_view methodName) std::string unimplemented_method::getMessage(std::string_view methodName) noexcept { - using namespace std::literals; - - std::ostringstream oss; - - oss << methodName << R"ex( is not implemented)ex"sv; - - return oss.str(); + return std::format(R"ex({} is not implemented)ex", methodName); } void await_worker_thread::await_suspend(std::coroutine_handle<> h) const @@ -371,12 +365,10 @@ void ValueVisitor::visitVariable(const peg::ast_node& variable) if (itr == _variables.get().cend()) { auto position = variable.begin(); - std::ostringstream error; - - error << "Unknown variable name: " << name; + auto error = std::format("Unknown variable name: {}", name); throw schema_exception { - { schema_error { error.str(), { position.line, position.column } } } + { schema_error { std::move(error), { position.line, position.column } } } }; } @@ -535,11 +527,9 @@ bool DirectiveVisitor::shouldSkip() const if (arguments.type() != response::Type::Map) { - std::ostringstream error; - - error << "Invalid arguments to directive: " << directiveName; + auto error = std::format("Invalid arguments to directive: {}", directiveName); - throw schema_exception { { error.str() } }; + throw schema_exception { { std::move(error) } }; } bool argumentTrue = false; @@ -550,12 +540,11 @@ bool DirectiveVisitor::shouldSkip() const if (argumentTrue || argumentFalse || argumentValue.type() != response::Type::Boolean || argumentName != "if") { - std::ostringstream error; - - error << "Invalid argument to directive: " << directiveName - << " name: " << argumentName; + auto error = std::format("Invalid argument to directive: {} name: {}", + directiveName, + argumentName); - throw schema_exception { { error.str() } }; + throw schema_exception { { std::move(error) } }; } argumentTrue = argumentValue.get(); @@ -572,11 +561,9 @@ bool DirectiveVisitor::shouldSkip() const } else { - std::ostringstream error; + auto error = std::format("Missing argument directive: {} name: if", directiveName); - error << "Missing argument directive: " << directiveName << " name: if"; - - throw schema_exception { { error.str() } }; + throw schema_exception { { std::move(error) } }; } } @@ -700,11 +687,9 @@ void blockSubFields(const ResolverParams& params) if (params.selection != nullptr) { auto position = params.selection->begin(); - std::ostringstream error; - - error << "Field may not have sub-fields name: " << params.fieldName; + auto error = std::format("Field may not have sub-fields name: {}", params.fieldName); - throw schema_exception { { schema_error { error.str(), + throw schema_exception { { schema_error { std::move(error), { position.line, position.column }, buildErrorPath(params.errorPath) } } }; } @@ -791,11 +776,9 @@ void requireSubFields(const ResolverParams& params) if (params.selection == nullptr) { auto position = params.field.begin(); - std::ostringstream error; - - error << "Field must have sub-fields name: " << params.fieldName; + auto error = std::format("Field must have sub-fields name: {}", params.fieldName); - throw schema_exception { { schema_error { error.str(), + throw schema_exception { { schema_error { std::move(error), { position.line, position.column }, buildErrorPath(params.errorPath) } } }; } @@ -1007,12 +990,10 @@ void SelectionVisitor::visitField(const peg::ast_node& field) { std::promise promise; auto position = field.begin(); - std::ostringstream error; - - error << "Unknown field name: " << name; + auto error = std::format("Unknown field name: {}", name); promise.set_exception( - std::make_exception_ptr(schema_exception { { schema_error { error.str(), + std::make_exception_ptr(schema_exception { { schema_error { std::move(error), { position.line, position.column }, buildErrorPath(_path ? std::make_optional(_path->get()) : std::nullopt) } } })); @@ -1101,12 +1082,10 @@ void SelectionVisitor::visitField(const peg::ast_node& field) catch (const std::exception& ex) { std::promise promise; - std::ostringstream message; - - message << "Field error name: " << alias << " unknown error: " << ex.what(); + auto message = std::format("Field error name: {} unknown error: ", alias, ex.what()); promise.set_exception( - std::make_exception_ptr(schema_exception { { schema_error { message.str(), + std::make_exception_ptr(schema_exception { { schema_error { std::move(message), { position.line, position.column }, buildErrorPath(selectionSetParams.errorPath) } } })); @@ -1122,11 +1101,9 @@ void SelectionVisitor::visitFragmentSpread(const peg::ast_node& fragmentSpread) if (itr == _fragments.end()) { auto position = fragmentSpread.begin(); - std::ostringstream error; + auto error = std::format("Unknown fragment name: {}", name); - error << "Unknown fragment name: " << name; - - throw schema_exception { { schema_error { error.str(), + throw schema_exception { { schema_error { std::move(error), { position.line, position.column }, buildErrorPath(_path ? std::make_optional(_path->get()) : std::nullopt) } } }; } @@ -1261,13 +1238,10 @@ AwaitableResolver Object::resolve(const SelectionSetParams& selectionSetParams, if (!document.data.emplace_back(std::string { child.name }, std::move(value.data))) { - std::ostringstream message; - - message << "Ambiguous field error name: " << child.name; - + auto message = std::format("Ambiguous field error name: {}", child.name); field_path path { parent, path_segment { child.name } }; - document.errors.push_back({ message.str(), + document.errors.push_back({ std::move(message), child.location.value_or(schema_location {}), buildErrorPath(std::make_optional(path)) }); } @@ -1290,13 +1264,11 @@ AwaitableResolver Object::resolve(const SelectionSetParams& selectionSetParams, } catch (const std::exception& ex) { - std::ostringstream message; - - message << "Field error name: " << child.name << " unknown error: " << ex.what(); - + auto message = + std::format("Field error name: {} unknown error: {}", child.name, ex.what()); field_path path { parent, path_segment { child.name } }; - document.errors.push_back({ message.str(), + document.errors.push_back({ std::move(message), child.location.value_or(schema_location {}), buildErrorPath(std::make_optional(path)) }); document.data.emplace_back(std::string { child.name }, {}); @@ -1598,12 +1570,10 @@ void SubscriptionDefinitionVisitor::visitField(const peg::ast_node& field) if (!_field.empty()) { auto position = field.begin(); - std::ostringstream error; - - error << "Extra subscription root field name: " << name; + auto error = std::format("Extra subscription root field name: {}", name); throw schema_exception { - { schema_error { error.str(), { position.line, position.column } } } + { schema_error { std::move(error), { position.line, position.column } } } }; } @@ -1645,12 +1615,10 @@ void SubscriptionDefinitionVisitor::visitFragmentSpread(const peg::ast_node& fra if (itr == _fragments.end()) { auto position = fragmentSpread.begin(); - std::ostringstream error; - - error << "Unknown fragment name: " << name; + auto error = std::format("Unknown fragment name: {}", name); throw schema_exception { - { schema_error { error.str(), { position.line, position.column } } } + { schema_error { std::move(error), { position.line, position.column } } } }; } @@ -1798,31 +1766,27 @@ response::AwaitableValue Request::resolve(RequestResolveParams params) const if (!operationDefinition) { - std::ostringstream message; - - message << "Missing operation"; + auto message = "Missing operation"s; if (!params.operationName.empty()) { - message << " name: " << params.operationName; + message += std::format(" name: {}", params.operationName); } - throw schema_exception { { message.str() } }; + throw schema_exception { { std::move(message) } }; } else if (operationType == strSubscription) { auto position = operationDefinition->begin(); - std::ostringstream message; - - message << "Unexpected subscription"; + auto message = "Unexpected subscription"s; if (!params.operationName.empty()) { - message << " name: " << params.operationName; + message += std::format(" name: {}", params.operationName); } throw schema_exception { - { schema_error { message.str(), { position.line, position.column } } } + { schema_error { std::move(message), { position.line, position.column } } } }; } @@ -2076,31 +2040,27 @@ SubscriptionKey Request::addSubscription(RequestSubscribeParams&& params) if (!operationDefinition) { - std::ostringstream message; - - message << "Missing subscription"; + auto message = "Missing subscription"s; if (!params.operationName.empty()) { - message << " name: " << params.operationName; + message += std::format(" name: {}", params.operationName); } - throw schema_exception { { message.str() } }; + throw schema_exception { { std::move(message) } }; } else if (operationType != strSubscription) { auto position = operationDefinition->begin(); - std::ostringstream message; - - message << "Unexpected operation type: " << operationType; + auto message = std::format("Unexpected operation type: {}", operationType); if (!params.operationName.empty()) { - message << " name: " << params.operationName; + message += std::format(" name: {}", params.operationName); } throw schema_exception { - { schema_error { message.str(), { position.line, position.column } } } + { schema_error { std::move(message), { position.line, position.column } } } }; } diff --git a/src/RequestLoader.cpp b/src/RequestLoader.cpp index 2673c707..0e59f661 100644 --- a/src/RequestLoader.cpp +++ b/src/RequestLoader.cpp @@ -733,16 +733,14 @@ void RequestLoader::findOperation() if (_operations.empty()) { - std::ostringstream message; - - message << "Missing operation"; + auto message = "Missing operation"s; if (_requestOptions.operationName && !_requestOptions.operationName->empty()) { - message << " name: " << *_requestOptions.operationName; + message += std::format(" name: {}", *_requestOptions.operationName); } - throw service::schema_exception { { message.str() } }; + throw service::schema_exception { { std::move(message) } }; } std::list errors; @@ -764,17 +762,15 @@ void RequestLoader::findOperation() if (!operation.responseType.type) { - std::ostringstream message; const auto position = operation.operation->begin(); - - message << "Unsupported operation type: " << operation.type; + auto message = std::format("Unsupported operation type: {}", operation.type); if (!operation.name.empty()) { - message << " name: " << operation.name; + message += std::format(" name: {}", operation.name); } - service::schema_error error { message.str(), + service::schema_error error { std::move(message), service::schema_location { position.line, position.column } }; errors.push_back(std::move(error)); @@ -842,12 +838,11 @@ void RequestLoader::collectVariables(Operation& operation) noexcept && variable.defaultValue.type() == response::Type::Null && (modifiers.empty() || modifiers.front() != service::TypeModifier::Nullable)) { - std::ostringstream error; - - error << "Expected Non-Null default value for variable name: " << variable.name; + auto error = std::format("Expected Non-Null default value for variable name: {}", + variable.name); throw service::schema_exception { - { service::schema_error { error.str(), std::move(defaultValueLocation) } } + { service::schema_error { std::move(error), std::move(defaultValueLocation) } } }; } @@ -945,11 +940,9 @@ void RequestLoader::reorderInputTypeDependencies(Operation& operation) // input types which are referenced in the request. if (itrDependent == itr) { - std::ostringstream error; + const auto error = std::format("Input object cycle type: {}", itr->type->name()); - error << "Input object cycle type: " << itr->type; - - throw std::logic_error(error.str()); + throw std::logic_error(error); } if (itrDependent != operation.referencedInputTypes.end()) @@ -1181,12 +1174,10 @@ void RequestLoader::SelectionVisitor::visitFragmentSpread(const peg::ast_node& f if (itr == _fragments.end()) { auto position = fragmentSpread.begin(); - std::ostringstream error; - - error << "Unknown fragment name: " << name; + auto error = std::format("Unknown fragment name: {}", name); throw service::schema_exception { - { service::schema_error { error.str(), { position.line, position.column } } } + { service::schema_error { std::move(error), { position.line, position.column } } } }; } diff --git a/src/SchemaGenerator.cpp b/src/SchemaGenerator.cpp index d0d26f18..eda453eb 100644 --- a/src/SchemaGenerator.cpp +++ b/src/SchemaGenerator.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -687,11 +688,7 @@ GRAPHQLSERVICE_EXPORT )cpp" << _loader.getSchemaNamespace() bool Generator::outputModule() const noexcept { std::ofstream moduleFile(_modulePath, std::ios_base::trunc); - std::ostringstream ossNamespace; - - ossNamespace << R"cpp(graphql::)cpp" << _loader.getSchemaNamespace(); - - const auto schemaNamespace = ossNamespace.str(); + const auto schemaNamespace = std::format(R"cpp(graphql::{})cpp", _loader.getSchemaNamespace()); moduleFile << R"cpp(// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. @@ -1382,13 +1379,10 @@ void Generator::outputObjectDeclaration( std::string Generator::getFieldDeclaration(const InputField& inputField) const noexcept { - std::ostringstream output; - - output << R"cpp( )cpp" << _loader.getInputCppType(inputField) << R"cpp( )cpp" - << inputField.cppName << R"cpp(; -)cpp"; - - return output.str(); + return std::format(R"cpp( {} {}; +)cpp", + _loader.getInputCppType(inputField), + inputField.cppName); } std::string Generator::getFieldDeclaration(const OutputField& outputField) const noexcept @@ -1425,14 +1419,12 @@ std::string Generator::getFieldDeclaration(const OutputField& outputField) const std::string Generator::getResolverDeclaration(const OutputField& outputField) const noexcept { - std::ostringstream output; const auto resolverName = SchemaLoader::getOutputCppResolver(outputField); - output << R"cpp( [[nodiscard("unnecessary call")]] service::AwaitableResolver )cpp" - << resolverName << R"cpp((service::ResolverParams&& params) const; -)cpp"; - - return output.str(); + return std::format( + R"cpp( [[nodiscard("unnecessary call")]] service::AwaitableResolver {}(service::ResolverParams&& params) const; +)cpp", + resolverName); } bool Generator::outputSource() const noexcept @@ -1484,7 +1476,6 @@ bool Generator::outputSource() const noexcept #include #include #include -#include #include #include #include @@ -2520,13 +2511,12 @@ service::ResolverMap )cpp" std::inserter(resolvers, resolvers.begin()), [](const OutputField& outputField) noexcept { const auto resolverName = SchemaLoader::getOutputCppResolver(outputField); - std::ostringstream output; - - output << R"cpp( { R"gql()cpp" << outputField.name - << R"cpp()gql"sv, [this](service::ResolverParams&& params) { return )cpp" - << resolverName << R"cpp((std::move(params)); } })cpp"; + auto output = std::format( + R"cpp( {{ R"gql({})gql"sv, [this](service::ResolverParams&& params) {{ return {}(std::move(params)); }} }})cpp", + outputField.name, + resolverName); - return std::make_pair(std::string_view { outputField.name }, output.str()); + return std::make_pair(std::string_view { outputField.name }, std::move(output)); }); resolvers["__typename"sv] = @@ -3229,16 +3219,8 @@ std::vector Generator::outputSeparateFiles() const noexcept } } - std::ostringstream ossNamespace; - - ossNamespace << R"cpp(graphql::)cpp" << _loader.getSchemaNamespace(); - - const auto schemaNamespace = ossNamespace.str(); - std::ostringstream ossInterfaceNamespace; - - ossInterfaceNamespace << schemaNamespace << R"cpp(::object)cpp"; - - const auto objectNamespace = ossInterfaceNamespace.str(); + const auto schemaNamespace = std::format(R"cpp(graphql::{})cpp", _loader.getSchemaNamespace()); + const auto objectNamespace = std::format(R"cpp({}::object)cpp", schemaNamespace); for (const auto& interfaceType : _loader.getInterfaceTypes()) { @@ -3439,11 +3421,8 @@ using namespace std::literals; } // Output the stub concepts - std::ostringstream ossConceptNamespace; - - ossConceptNamespace << R"cpp(methods::)cpp" << objectType.cppType << R"cpp(Has)cpp"; - - const auto conceptNamespace = ossConceptNamespace.str(); + const auto conceptNamespace = + std::format(R"cpp(methods::{}Has)cpp", objectType.cppType); NamespaceScope stubNamespace { headerFile, conceptNamespace }; outputObjectStubs(headerFile, objectType); @@ -3534,7 +3513,6 @@ using namespace std::literals; sourceFile << R"cpp( #include #include -#include #include #include diff --git a/src/SchemaLoader.cpp b/src/SchemaLoader.cpp index e6c4be43..85bbaa63 100644 --- a/src/SchemaLoader.cpp +++ b/src/SchemaLoader.cpp @@ -78,18 +78,17 @@ void SchemaLoader::validateSchema() { if (s_builtinTypes.find(entry.first) != s_builtinTypes.cend()) { - std::ostringstream error; auto itrPosition = _typePositions.find(entry.first); - - error << "Builtin type overridden: " << entry.first; + auto error = std::format("Builtin type overridden: {}", entry.first); if (itrPosition != _typePositions.cend()) { - error << " line: " << itrPosition->second.line - << " column: " << itrPosition->second.column; + error += std::format(" line: {} column: {}", + itrPosition->second.line, + itrPosition->second.column); } - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } } @@ -149,12 +148,11 @@ void SchemaLoader::validateSchema() { if (_objectNames.find(operation.type) == _objectNames.cend()) { - std::ostringstream error; - - error << "Unknown operation type: " << operation.type - << " operation: " << operation.operation; + const auto error = std::format("Unknown operation type: {} operation: {}", + operation.type, + operation.operation); - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } queryDefined = queryDefined || (operation.operation == service::strQuery); @@ -215,18 +213,18 @@ void SchemaLoader::validateSchema() if (itr == _objectNames.cend()) { - std::ostringstream error; auto itrPosition = _typePositions.find(entry.type); - - error << "Unknown type: " << objectName << " included by: " << entry.type; + auto error = + std::format("Unknown type: {} included by: {}", objectName, entry.type); if (itrPosition != _typePositions.cend()) { - error << " line: " << itrPosition->second.line - << " column: " << itrPosition->second.column; + error += std::format(" line: {} column: {}", + itrPosition->second.line, + itrPosition->second.column); } - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } _objectTypes[itr->second].unions.push_back(entry.type); @@ -265,16 +263,16 @@ void SchemaLoader::fixupOutputFieldList(OutputFieldList& fields, if (itr == _schemaTypes.cend()) { - std::ostringstream error; - - error << "Unknown field type: " << entry.type; + auto error = std::format("Unknown field type: {}", entry.type); if (entry.position) { - error << " line: " << entry.position->line << " column: " << entry.position->column; + error += std::format(" line: {} column: {}", + entry.position->line, + entry.position->column); } - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } switch (itr->second) @@ -301,17 +299,16 @@ void SchemaLoader::fixupOutputFieldList(OutputFieldList& fields, default: { - std::ostringstream error; - - error << "Invalid field type: " << entry.type; + auto error = std::format("Invalid field type: {}", entry.type); if (entry.position) { - error << " line: " << entry.position->line - << " column: " << entry.position->column; + error += std::format(" line: {} column: {}", + entry.position->line, + entry.position->column); } - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } } @@ -332,16 +329,16 @@ void SchemaLoader::fixupInputFieldList(InputFieldList& fields) if (itr == _schemaTypes.cend()) { - std::ostringstream error; - - error << "Unknown argument type: " << entry.type; + auto error = std::format("Unknown argument type: {}", entry.type); if (entry.position) { - error << " line: " << entry.position->line << " column: " << entry.position->column; + error += std::format(" line: {} column: {}", + entry.position->line, + entry.position->column); } - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } switch (itr->second) @@ -360,17 +357,16 @@ void SchemaLoader::fixupInputFieldList(InputFieldList& fields) default: { - std::ostringstream error; - - error << "Invalid argument type: " << entry.type; + auto error = std::format("Invalid argument type: {}", entry.type); if (entry.position) { - error << " line: " << entry.position->line - << " column: " << entry.position->column; + error += std::format(" line: {} column: {}", + entry.position->line, + entry.position->column); } - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } } } @@ -417,11 +413,9 @@ void SchemaLoader::reorderInputTypeDependencies() // Check to make sure we made progress. if (itrDependent == itr) { - std::ostringstream error; - - error << "Input object cycle type: " << itr->type; + const auto error = std::format("Input object cycle type: {}", itr->type); - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } if (itrDependent != _inputTypes.end()) @@ -534,12 +528,11 @@ void SchemaLoader::visitDefinition(const peg::ast_node& definition) else { const auto position = definition.begin(); - std::ostringstream error; + const auto error = std::format("Unexpected executable definition line: {} column: {}", + position.line, + position.column); - error << "Unexpected executable definition line: " << position.line - << " column: " << position.column; - - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } } @@ -1287,16 +1280,14 @@ void SchemaLoader::blockReservedName( // https://spec.graphql.org/October2021/#sec-Names.Reserved-Names if (name.size() > 1 && name.substr(0, 2) == R"gql(__)gql"sv) { - std::ostringstream error; - - error << "Names starting with __ are reserved: " << name; + auto error = std::format("Names starting with __ are reserved: {}", name); if (position) { - error << " line: " << position->line << " column: " << position->column; + error += std::format(" line: {} column: {}", position->line, position->column); } - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } } @@ -1307,18 +1298,18 @@ const InterfaceType& SchemaLoader::findInterfaceType( if (itrType == _interfaceNames.cend()) { - std::ostringstream error; const auto itrPosition = _typePositions.find(typeName); - - error << "Unknown interface: " << interfaceName << " implemented by: " << typeName; + auto error = + std::format("Unknown interface: {} implemented by: {}", interfaceName, typeName); if (itrPosition != _typePositions.cend()) { - error << " line: " << itrPosition->second.line - << " column: " << itrPosition->second.column; + error += std::format(" line: {} column: {}", + itrPosition->second.line, + itrPosition->second.column); } - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } return _interfaceTypes[itrType->second]; @@ -1342,24 +1333,24 @@ void SchemaLoader::validateInterfaceFields(std::string_view typeName, if (!unimplemented.empty()) { - std::ostringstream error; const auto itrPosition = _typePositions.find(typeName); - - error << "Missing interface fields type: " << typeName - << " interface: " << interfaceType.type; + auto error = std::format("Missing interface fields type: {} interface: {}", + typeName, + interfaceType.type); if (itrPosition != _typePositions.cend()) { - error << " line: " << itrPosition->second.line - << " column: " << itrPosition->second.column; + error += std::format(" line: {} column: {}", + itrPosition->second.line, + itrPosition->second.column); } for (auto fieldName : unimplemented) { - error << " field: " << fieldName; + error += std::format(" field: {}", fieldName); } - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } } @@ -1382,18 +1373,17 @@ void SchemaLoader::validateTransitiveInterfaces( if (unimplemented.find(typeName) != unimplemented.cend()) { - std::ostringstream error; const auto itrPosition = _typePositions.find(typeName); - - error << "Interface cycle interface: " << typeName; + auto error = std::format("Interface cycle interface: {}", typeName); if (itrPosition != _typePositions.cend()) { - error << " line: " << itrPosition->second.line - << " column: " << itrPosition->second.column; + error += std::format(" line: {} column: {}", + itrPosition->second.line, + itrPosition->second.column); } - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } for (auto entry : interfaces) @@ -1403,23 +1393,22 @@ void SchemaLoader::validateTransitiveInterfaces( if (!unimplemented.empty()) { - std::ostringstream error; const auto itrPosition = _typePositions.find(typeName); - - error << "Missing transitive interface type: " << typeName; + auto error = std::format("Missing transitive interface type: {}", typeName); if (itrPosition != _typePositions.cend()) { - error << " line: " << itrPosition->second.line - << " column: " << itrPosition->second.column; + error += std::format(" line: {} column: {}", + itrPosition->second.line, + itrPosition->second.column); } for (auto interfaceName : unimplemented) { - error << " interface: " << interfaceName; + error += std::format(" interface: {}", interfaceName); } - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } } @@ -1548,13 +1537,13 @@ InputFieldList SchemaLoader::getInputFields(const peg::ast_node::children_t& fie && (field.modifiers.empty() || field.modifiers.front() != service::TypeModifier::Nullable)) { - std::ostringstream error; - - error << "Expected Non-Null default value for field name: " << field.name - << " line: " << defaultValueLocation.line - << " column: " << defaultValueLocation.column; + const auto error = std::format( + "Expected Non-Null default value for field name: {} line: {} column: {}", + field.name, + defaultValueLocation.line, + defaultValueLocation.column); - throw std::runtime_error(error.str()); + throw std::runtime_error(error); } inputFields.push_back(std::move(field)); diff --git a/src/SyntaxTree.cpp b/src/SyntaxTree.cpp index b0882ac1..f51dc4d3 100644 --- a/src/SyntaxTree.cpp +++ b/src/SyntaxTree.cpp @@ -9,12 +9,12 @@ #include #include +#include #include #include #include #include #include -#include #include using namespace std::literals; @@ -51,7 +51,7 @@ std::string_view ast_node::unescaped_view() const && child->children.front()->is_type() && child->children.back()->is_type()) ? std::make_optional(std::make_pair(child->children.front()->string_view(), - child->children.back()->unescaped_view())) + child->children.back()->unescaped_view())) : std::nullopt; }); @@ -674,12 +674,11 @@ struct ast_action : maybe_nothing depth_guard guard(in.selectionSetDepth); if (in.selectionSetDepth > in.depthLimit()) { - std::ostringstream oss; + const auto error = std::format("Exceeded nested depth limit: {} for " + "https://spec.graphql.org/October2021/#SelectionSet", + in.depthLimit()); - oss << "Exceeded nested depth limit: " << in.depthLimit() - << " for https://spec.graphql.org/October2021/#SelectionSet"; - - throw parse_error(oss.str(), in); + throw parse_error(error, in); } return tao::graphqlpeg::template match(in, st...); diff --git a/src/Validation.cpp b/src/Validation.cpp index 65204d9e..c560c8b3 100644 --- a/src/Validation.cpp +++ b/src/Validation.cpp @@ -246,11 +246,9 @@ void ValidateArgumentValueVisitor::visitObjectValue(const peg::ast_node& objectV { // https://spec.graphql.org/October2021/#sec-Input-Object-Field-Uniqueness auto fieldPosition = field->begin(); - std::ostringstream message; + auto message = std::format("Conflicting input field name: {}", name); - message << "Conflicting input field name: " << name; - - _errors.push_back({ message.str(), { fieldPosition.line, fieldPosition.column } }); + _errors.push_back({ std::move(message), { fieldPosition.line, fieldPosition.column } }); continue; } @@ -494,11 +492,9 @@ void ValidateExecutableVisitor::visit(const peg::ast_node& root) { // https://spec.graphql.org/October2021/#sec-Fragment-Name-Uniqueness auto position = fragmentDefinition.begin(); - std::ostringstream error; - - error << "Duplicate fragment name: " << inserted.first->first; + auto error = std::format("Duplicate fragment name: {}", inserted.first->first); - _errors.push_back({ error.str(), { position.line, position.column } }); + _errors.push_back({ std::move(error), { position.line, position.column } }); } }); @@ -518,11 +514,9 @@ void ValidateExecutableVisitor::visit(const peg::ast_node& root) { // https://spec.graphql.org/October2021/#sec-Operation-Name-Uniqueness auto position = operationDefinition.begin(); - std::ostringstream error; - - error << "Duplicate operation name: " << inserted.first->first; + auto error = std::format("Duplicate operation name: {}", inserted.first->first); - _errors.push_back({ error.str(), { position.line, position.column } }); + _errors.push_back({ std::move(error), { position.line, position.column } }); } }); @@ -579,11 +573,10 @@ void ValidateExecutableVisitor::visit(const peg::ast_node& root) std::back_inserter(_errors), [](const auto& fragmentDefinition) noexcept { auto position = fragmentDefinition.second.get().begin(); - std::ostringstream message; + auto message = + std::format("Unused fragment definition name: {}", fragmentDefinition.first); - message << "Unused fragment definition name: " << fragmentDefinition.first; - - return schema_error { message.str(), { position.line, position.column } }; + return schema_error { std::move(message), { position.line, position.column } }; }); } } @@ -619,13 +612,12 @@ void ValidateExecutableVisitor::visitFragmentDefinition(const peg::ast_node& fra // https://spec.graphql.org/October2021/#sec-Fragment-Spread-Type-Existence // https://spec.graphql.org/October2021/#sec-Fragments-On-Composite-Types auto position = typeCondition->begin(); - std::ostringstream message; - - message << (itrType == _types.end() ? "Undefined target type on fragment definition: " - : "Scalar target type on fragment definition: ") - << name << " name: " << innerType; + auto message = std::format("{} target type on fragment definition: {} name: {}", + (itrType == _types.end() ? "Undefined" : "Scalar"), + name, + innerType); - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); return; } @@ -657,100 +649,94 @@ void ValidateExecutableVisitor::visitOperationDefinition(const peg::ast_node& op _operationVariables = std::make_optional(); - peg::for_each_child(operationDefinition, - [this, operationName](const peg::ast_node& variable) { - std::string_view variableName; - ValidateArgument variableArgument; + peg::for_each_child< + peg::variable>(operationDefinition, [this, operationName](const peg::ast_node& variable) { + std::string_view variableName; + ValidateArgument variableArgument; - for (const auto& child : variable.children) + for (const auto& child : variable.children) + { + if (child->is_type()) { - if (child->is_type()) + // Skip the $ prefix + variableName = child->string_view().substr(1); + + if (_operationVariables->find(variableName) != _operationVariables->end()) { - // Skip the $ prefix - variableName = child->string_view().substr(1); + // https://spec.graphql.org/October2021/#sec-Variable-Uniqueness + auto position = child->begin(); + auto message = "Conflicting variable"s; - if (_operationVariables->find(variableName) != _operationVariables->end()) + if (!operationName.empty()) { - // https://spec.graphql.org/October2021/#sec-Variable-Uniqueness - auto position = child->begin(); - std::ostringstream message; + message += std::format(" operation: {}", operationName); + } - message << "Conflicting variable"; + message += std::format(" name: {}", variableName); - if (!operationName.empty()) - { - message << " operation: " << operationName; - } + _errors.push_back({ std::move(message), { position.line, position.column } }); + return; + } + } + else if (child->is_type() || child->is_type() + || child->is_type()) + { + ValidateVariableTypeVisitor visitor(_schema, _types); - message << " name: " << variableName; + visitor.visit(*child); - _errors.push_back({ message.str(), { position.line, position.column } }); - return; - } - } - else if (child->is_type() || child->is_type() - || child->is_type()) + if (!visitor.isInputType()) { - ValidateVariableTypeVisitor visitor(_schema, _types); + // https://spec.graphql.org/October2021/#sec-Variables-Are-Input-Types + auto position = child->begin(); + auto message = "Invalid variable type"s; - visitor.visit(*child); - - if (!visitor.isInputType()) + if (!operationName.empty()) { - // https://spec.graphql.org/October2021/#sec-Variables-Are-Input-Types - auto position = child->begin(); - std::ostringstream message; - - message << "Invalid variable type"; - - if (!operationName.empty()) - { - message << " operation: " << operationName; - } - - message << " name: " << variableName; - - _errors.push_back({ message.str(), { position.line, position.column } }); - return; + message += std::format(" operation: {}", operationName); } - variableArgument.type = visitor.getType(); - } - else if (child->is_type()) - { - ValidateArgumentValueVisitor visitor(_errors); - - visitor.visit(*child->children.back()); + message += std::format(" name: {}", variableName); - auto argument = visitor.getArgumentValue(); + _errors.push_back({ std::move(message), { position.line, position.column } }); + return; + } - if (!validateInputValue(false, argument, variableArgument.type)) - { - // https://spec.graphql.org/October2021/#sec-Values-of-Correct-Type - auto position = child->begin(); - std::ostringstream message; + variableArgument.type = visitor.getType(); + } + else if (child->is_type()) + { + ValidateArgumentValueVisitor visitor(_errors); - message << "Incompatible variable default value"; + visitor.visit(*child->children.back()); - if (!operationName.empty()) - { - message << " operation: " << operationName; - } + auto argument = visitor.getArgumentValue(); - message << " name: " << variableName; + if (!validateInputValue(false, argument, variableArgument.type)) + { + // https://spec.graphql.org/October2021/#sec-Values-of-Correct-Type + auto position = child->begin(); + auto message = "Incompatible variable default value"s; - _errors.push_back({ message.str(), { position.line, position.column } }); - return; + if (!operationName.empty()) + { + message += std::format(" operation: {}", operationName); } - variableArgument.defaultValue = true; - variableArgument.nonNullDefaultValue = argument.value != nullptr; + message += std::format(" name: {}", variableName); + + _errors.push_back({ std::move(message), { position.line, position.column } }); + return; } + + variableArgument.defaultValue = true; + variableArgument.nonNullDefaultValue = argument.value != nullptr; } + } - _variableDefinitions.emplace(variableName, variable); - _operationVariables->emplace(variableName, std::move(variableArgument)); - }); + _variableDefinitions.emplace(variableName, variable); + _operationVariables->emplace(variableName, std::move(variableArgument)); + }); peg::on_first_child(operationDefinition, [this, &operationType](const peg::ast_node& child) { @@ -773,11 +759,9 @@ void ValidateExecutableVisitor::visitOperationDefinition(const peg::ast_node& op if (itrType == _operationTypes.end()) { auto position = operationDefinition.begin(); - std::ostringstream error; + auto error = std::format("Unsupported operation type: {}", operationType); - error << "Unsupported operation type: " << operationType; - - _errors.push_back({ error.str(), { position.line, position.column } }); + _errors.push_back({ std::move(error), { position.line, position.column } }); return; } @@ -795,32 +779,28 @@ void ValidateExecutableVisitor::visitOperationDefinition(const peg::ast_node& op { // https://spec.graphql.org/October2021/#sec-Single-root-field auto position = operationDefinition.begin(); - std::ostringstream error; - - error << "Subscription with more than one root field"; + auto error = "Subscription with more than one root field"s; if (!operationName.empty()) { - error << " name: " << operationName; + error += std::format(" name: {}", operationName); } - _errors.push_back({ error.str(), { position.line, position.column } }); + _errors.push_back({ std::move(error), { position.line, position.column } }); } if (_introspectionFieldCount != 0) { // https://spec.graphql.org/October2021/#sec-Single-root-field auto position = operationDefinition.begin(); - std::ostringstream error; - - error << "Subscription with Introspection root field"; + auto error = "Subscription with Introspection root field"s; if (!operationName.empty()) { - error << " name: " << operationName; + error += std::format(" name: {}", operationName); } - _errors.push_back({ error.str(), { position.line, position.column } }); + _errors.push_back({ std::move(error), { position.line, position.column } }); } } @@ -834,11 +814,9 @@ void ValidateExecutableVisitor::visitOperationDefinition(const peg::ast_node& op { // https://spec.graphql.org/October2021/#sec-All-Variables-Used auto position = variable.second.get().begin(); - std::ostringstream error; - - error << "Unused variable name: " << variable.first; + auto error = std::format("Unused variable name: {}", variable.first); - _errors.push_back({ error.str(), { position.line, position.column } }); + _errors.push_back({ std::move(error), { position.line, position.column } }); } } @@ -948,11 +926,9 @@ bool ValidateExecutableVisitor::validateInputValue( if (itrVariable == _operationVariables->end()) { // https://spec.graphql.org/October2021/#sec-All-Variable-Uses-Defined - std::ostringstream message; - - message << "Undefined variable name: " << variable.name; + auto message = std::format("Undefined variable name: {}", variable.name); - _errors.push_back({ message.str(), argument.position }); + _errors.push_back({ std::move(message), argument.position }); return false; } @@ -1045,11 +1021,9 @@ bool ValidateExecutableVisitor::validateInputValue( if (!std::holds_alternative(argument.value->data)) { - std::ostringstream message; + auto message = std::format("Expected Input Object value name: {}", name); - message << "Expected Input Object value name: " << name; - - _errors.push_back({ message.str(), argument.position }); + _errors.push_back({ std::move(message), argument.position }); return false; } @@ -1057,11 +1031,9 @@ bool ValidateExecutableVisitor::validateInputValue( if (itrFields == _inputTypeFields.end()) { - std::ostringstream message; - - message << "Expected Input Object fields name: " << name; + auto message = std::format("Expected Input Object fields name: {}", name); - _errors.push_back({ message.str(), argument.position }); + _errors.push_back({ std::move(message), argument.position }); return false; } @@ -1076,12 +1048,11 @@ bool ValidateExecutableVisitor::validateInputValue( if (itrField == itrFields->second.end()) { // https://spec.graphql.org/October2021/#sec-Input-Object-Field-Names - std::ostringstream message; + auto message = std::format("Undefined Input Object field type: {} name: {}", + name, + entry.first); - message << "Undefined Input Object field type: " << name - << " name: " << entry.first; - - _errors.push_back({ message.str(), entry.second.position }); + _errors.push_back({ std::move(message), entry.second.position }); return false; } @@ -1113,12 +1084,11 @@ bool ValidateExecutableVisitor::validateInputValue( if (!entry.second.type) { - std::ostringstream message; - - message << "Unknown Input Object field type: " << name - << " name: " << entry.first; + auto message = std::format("Unknown Input Object field type: {} name: {}", + name, + entry.first); - _errors.push_back({ message.str(), argument.position }); + _errors.push_back({ std::move(message), argument.position }); return false; } @@ -1127,12 +1097,11 @@ bool ValidateExecutableVisitor::validateInputValue( if (fieldKind == introspection::TypeKind::NON_NULL) { // https://spec.graphql.org/October2021/#sec-Input-Object-Required-Fields - std::ostringstream message; - - message << "Missing Input Object field type: " << name - << " name: " << entry.first; + auto message = std::format("Missing Input Object field type: {} name: {}", + name, + entry.first); - _errors.push_back({ message.str(), argument.position }); + _errors.push_back({ std::move(message), argument.position }); return false; } } @@ -1152,11 +1121,9 @@ bool ValidateExecutableVisitor::validateInputValue( if (!std::holds_alternative(argument.value->data)) { - std::ostringstream message; + auto message = std::format("Expected Enum value name: {}", name); - message << "Expected Enum value name: " << name; - - _errors.push_back({ message.str(), argument.position }); + _errors.push_back({ std::move(message), argument.position }); return false; } @@ -1166,11 +1133,9 @@ bool ValidateExecutableVisitor::validateInputValue( if (itrEnumValues == _enumValues.end() || itrEnumValues->second.find(value) == itrEnumValues->second.end()) { - std::ostringstream message; - - message << "Undefined Enum value type: " << name << " name: " << value; + auto message = std::format("Undefined Enum value type: {} name: {}", name, value); - _errors.push_back({ message.str(), argument.position }); + _errors.push_back({ std::move(message), argument.position }); return false; } @@ -1231,11 +1196,9 @@ bool ValidateExecutableVisitor::validateInputValue( if (_scalarTypes.find(name) == _scalarTypes.end()) { - std::ostringstream message; + auto message = std::format("Undefined Scalar type name: {}", name); - message << "Undefined Scalar type name: " << name; - - _errors.push_back({ message.str(), argument.position }); + _errors.push_back({ std::move(message), argument.position }); return false; } @@ -1398,11 +1361,10 @@ bool ValidateExecutableVisitor::validateVariableType(bool isNonNull, if (variableName != inputName) { // https://spec.graphql.org/October2021/#sec-All-Variable-Usages-are-Allowed - std::ostringstream message; - - message << "Incompatible variable type: " << variableName << " name: " << inputName; + auto message = + std::format("Incompatible variable type: {} name: {}", variableName, inputName); - _errors.push_back({ message.str(), position }); + _errors.push_back({ std::move(message), position }); return false; } @@ -1563,11 +1525,10 @@ void ValidateExecutableVisitor::visitField(const peg::ast_node& field) { // https://spec.graphql.org/October2021/#sec-Leaf-Field-Selections auto position = field.begin(); - std::ostringstream message; + auto message = + std::format("Field on scalar type: {} name: {}", _scopedType->get().name(), name); - message << "Field on scalar type: " << _scopedType->get().name() << " name: " << name; - - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); return; } @@ -1591,12 +1552,11 @@ void ValidateExecutableVisitor::visitField(const peg::ast_node& field) { // https://spec.graphql.org/October2021/#sec-Leaf-Field-Selections auto position = field.begin(); - std::ostringstream message; - - message << "Field on union type: " << _scopedType->get().name() - << " name: " << name; + auto message = std::format("Field on union type: {} name: {}", + _scopedType->get().name(), + name); - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); return; } @@ -1615,11 +1575,10 @@ void ValidateExecutableVisitor::visitField(const peg::ast_node& field) { // https://spec.graphql.org/October2021/#sec-Field-Selections auto position = field.begin(); - std::ostringstream message; + auto message = + std::format("Undefined field type: {} name: {}", _scopedType->get().name(), name); - message << "Undefined field type: " << _scopedType->get().name() << " name: " << name; - - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); return; } @@ -1649,12 +1608,12 @@ void ValidateExecutableVisitor::visitField(const peg::ast_node& field) if (validateArguments.find(argumentName) != validateArguments.end()) { // https://spec.graphql.org/October2021/#sec-Argument-Uniqueness - std::ostringstream message; - - message << "Conflicting argument type: " << _scopedType->get().name() - << " field: " << name << " name: " << argumentName; + auto message = std::format("Conflicting argument type: {} field: {} name: {}", + _scopedType->get().name(), + name, + argumentName); - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); continue; } @@ -1687,11 +1646,10 @@ void ValidateExecutableVisitor::visitField(const peg::ast_node& field) { // https://spec.graphql.org/October2021/#sec-Field-Selection-Merging auto position = field.begin(); - std::ostringstream message; - - message << "Conflicting field type: " << _scopedType->get().name() << " name: " << name; + auto message = + std::format("Conflicting field type: {} name: {}", _scopedType->get().name(), name); - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); } } @@ -1706,12 +1664,12 @@ void ValidateExecutableVisitor::visitField(const peg::ast_node& field) if (itrArgument == itrField->second.arguments.end()) { // https://spec.graphql.org/October2021/#sec-Argument-Names - std::ostringstream message; + auto message = std::format("Undefined argument type: {} field: {} name: {}", + _scopedType->get().name(), + name, + argumentName); - message << "Undefined argument type: " << _scopedType->get().name() - << " field: " << name << " name: " << argumentName; - - _errors.push_back({ message.str(), argumentLocations[argumentName] }); + _errors.push_back({ std::move(message), argumentLocations[argumentName] }); } } @@ -1728,12 +1686,12 @@ void ValidateExecutableVisitor::visitField(const peg::ast_node& field) argument.second.type)) { // https://spec.graphql.org/October2021/#sec-Values-of-Correct-Type - std::ostringstream message; - - message << "Incompatible argument type: " << _scopedType->get().name() - << " field: " << name << " name: " << argument.first; + auto message = std::format("Incompatible argument type: {} field: {} name: {}", + _scopedType->get().name(), + name, + argument.first); - _errors.push_back({ message.str(), argumentLocations[argument.first] }); + _errors.push_back({ std::move(message), argumentLocations[argument.first] }); } continue; @@ -1750,14 +1708,13 @@ void ValidateExecutableVisitor::visitField(const peg::ast_node& field) { // https://spec.graphql.org/October2021/#sec-Required-Arguments auto position = field.begin(); - std::ostringstream message; + auto message = std::format("{} argument type: {} field: {} name: {}", + (missing ? "Missing" : "Required non-null"), + _scopedType->get().name(), + name, + argument.first); - message << (missing ? "Missing argument type: " - : "Required non-null argument type: ") - << _scopedType->get().name() << " field: " << name - << " name: " << argument.first; - - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); } } } @@ -1798,11 +1755,10 @@ void ValidateExecutableVisitor::visitField(const peg::ast_node& field) { // https://spec.graphql.org/October2021/#sec-Leaf-Field-Selections auto position = field.begin(); - std::ostringstream message; - - message << "Missing fields on non-scalar type: " << innerType->get().name(); + auto message = + std::format("Missing fields on non-scalar type: {}", innerType->get().name()); - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); return; } @@ -1830,11 +1786,9 @@ void ValidateExecutableVisitor::visitFragmentSpread(const peg::ast_node& fragmen { // https://spec.graphql.org/October2021/#sec-Fragment-spread-target-defined auto position = fragmentSpread.begin(); - std::ostringstream message; - - message << "Undefined fragment spread name: " << name; + auto message = std::format("Undefined fragment spread name: {}", name); - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); return; } @@ -1844,11 +1798,9 @@ void ValidateExecutableVisitor::visitFragmentSpread(const peg::ast_node& fragmen { // https://spec.graphql.org/October2021/#sec-Fragment-spreads-must-not-form-cycles auto position = fragmentSpread.begin(); - std::ostringstream message; + auto message = std::format("Cyclic fragment spread name: {}", name); - message << "Cyclic fragment spread name: " << name; - - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); } return; @@ -1863,11 +1815,10 @@ void ValidateExecutableVisitor::visitFragmentSpread(const peg::ast_node& fragmen { // https://spec.graphql.org/October2021/#sec-Fragment-spread-is-possible auto position = fragmentSpread.begin(); - std::ostringstream message; - - message << "Incompatible fragment spread target type: " << innerType << " name: " << name; + auto message = + std::format("Incompatible fragment spread target type: {} name: {}", innerType, name); - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); return; } @@ -1914,11 +1865,10 @@ void ValidateExecutableVisitor::visitInlineFragment(const peg::ast_node& inlineF if (itrInner == _types.end()) { // https://spec.graphql.org/October2021/#sec-Fragment-Spread-Type-Existence - std::ostringstream message; + auto message = + std::format("Undefined target type on inline fragment name: {}", innerType); - message << "Undefined target type on inline fragment name: " << innerType; - - _errors.push_back({ message.str(), std::move(typeConditionLocation) }); + _errors.push_back({ std::move(message), std::move(typeConditionLocation) }); return; } @@ -1928,14 +1878,11 @@ void ValidateExecutableVisitor::visitInlineFragment(const peg::ast_node& inlineF { // https://spec.graphql.org/October2021/#sec-Fragments-On-Composite-Types // https://spec.graphql.org/October2021/#sec-Fragment-spread-is-possible - std::ostringstream message; - - message << (isScalarType(fragmentType->get().kind()) - ? "Scalar target type on inline fragment name: " - : "Incompatible target type on inline fragment name: ") - << innerType; + auto message = std::format("{} target type on inline fragment name: {}", + (isScalarType(fragmentType->get().kind()) ? "Scalar" : "Incompatible"), + innerType); - _errors.push_back({ message.str(), std::move(typeConditionLocation) }); + _errors.push_back({ std::move(message), std::move(typeConditionLocation) }); return; } } @@ -1972,11 +1919,9 @@ void ValidateExecutableVisitor::visitDirectives( { // https://spec.graphql.org/October2021/#sec-Directives-Are-Defined auto position = directive->begin(); - std::ostringstream message; - - message << "Undefined directive name: " << directiveName; + auto message = std::format("Undefined directive name: {}", directiveName); - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); continue; } @@ -1984,11 +1929,9 @@ void ValidateExecutableVisitor::visitDirectives( { // https://spec.graphql.org/October2021/#sec-Directives-Are-Unique-Per-Location auto position = directive->begin(); - std::ostringstream message; + auto message = std::format("Conflicting directive name: {}", directiveName); - message << "Conflicting directive name: " << directiveName; - - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); continue; } @@ -1996,45 +1939,43 @@ void ValidateExecutableVisitor::visitDirectives( { // https://spec.graphql.org/October2021/#sec-Directives-Are-In-Valid-Locations auto position = directive->begin(); - std::ostringstream message; - - message << "Unexpected location for directive: " << directiveName; + auto message = std::format("Unexpected location for directive: {}", directiveName); switch (location) { case introspection::DirectiveLocation::QUERY: - message << " name: QUERY"; + message += " name: QUERY"; break; case introspection::DirectiveLocation::MUTATION: - message << " name: MUTATION"; + message += " name: MUTATION"; break; case introspection::DirectiveLocation::SUBSCRIPTION: - message << " name: SUBSCRIPTION"; + message += " name: SUBSCRIPTION"; break; case introspection::DirectiveLocation::FIELD: - message << " name: FIELD"; + message += " name: FIELD"; break; case introspection::DirectiveLocation::FRAGMENT_DEFINITION: - message << " name: FRAGMENT_DEFINITION"; + message += " name: FRAGMENT_DEFINITION"; break; case introspection::DirectiveLocation::FRAGMENT_SPREAD: - message << " name: FRAGMENT_SPREAD"; + message += " name: FRAGMENT_SPREAD"; break; case introspection::DirectiveLocation::INLINE_FRAGMENT: - message << " name: INLINE_FRAGMENT"; + message += " name: INLINE_FRAGMENT"; break; default: break; } - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back({ std::move(message), { position.line, position.column } }); continue; } @@ -2052,12 +1993,12 @@ void ValidateExecutableVisitor::visitDirectives( if (validateArguments.find(argumentName) != validateArguments.end()) { // https://spec.graphql.org/October2021/#sec-Argument-Uniqueness - std::ostringstream message; + auto message = std::format("Conflicting argument directive: {} name: {}", + directiveName, + argumentName); - message << "Conflicting argument directive: " << directiveName - << " name: " << argumentName; - - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back( + { std::move(message), { position.line, position.column } }); continue; } @@ -2076,12 +2017,11 @@ void ValidateExecutableVisitor::visitDirectives( if (itrArgument == itrDirective->second.arguments.end()) { // https://spec.graphql.org/October2021/#sec-Argument-Names - std::ostringstream message; - - message << "Undefined argument directive: " << directiveName - << " name: " << argumentName; + auto message = std::format("Undefined argument directive: {} name: {}", + directiveName, + argumentName); - _errors.push_back({ message.str(), argumentLocations[argumentName] }); + _errors.push_back({ std::move(message), argumentLocations[argumentName] }); } } @@ -2098,12 +2038,13 @@ void ValidateExecutableVisitor::visitDirectives( argument.second.type)) { // https://spec.graphql.org/October2021/#sec-Values-of-Correct-Type - std::ostringstream message; + auto message = + std::format("Incompatible argument directive: {} name: {}", + directiveName, + argument.first); - message << "Incompatible argument directive: " << directiveName - << " name: " << argument.first; - - _errors.push_back({ message.str(), argumentLocations[argument.first] }); + _errors.push_back( + { std::move(message), argumentLocations[argument.first] }); } continue; @@ -2120,13 +2061,13 @@ void ValidateExecutableVisitor::visitDirectives( { // https://spec.graphql.org/October2021/#sec-Required-Arguments auto position = directive->begin(); - std::ostringstream message; - - message << (missing ? "Missing argument directive: " - : "Required non-null argument directive: ") - << directiveName << " name: " << argument.first; + auto message = std::format("{} argument directive: {} name: {}", + (missing ? "Missing" : "Required non-null"), + directiveName, + argument.first); - _errors.push_back({ message.str(), { position.line, position.column } }); + _errors.push_back( + { std::move(message), { position.line, position.column } }); } } }); diff --git a/src/introspection/DirectiveObject.cpp b/src/introspection/DirectiveObject.cpp index 7f1c19be..4da18e52 100644 --- a/src/introspection/DirectiveObject.cpp +++ b/src/introspection/DirectiveObject.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include diff --git a/src/introspection/EnumValueObject.cpp b/src/introspection/EnumValueObject.cpp index 85ff0ca5..7cdb6386 100644 --- a/src/introspection/EnumValueObject.cpp +++ b/src/introspection/EnumValueObject.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include diff --git a/src/introspection/FieldObject.cpp b/src/introspection/FieldObject.cpp index cd50b6b6..4a6dc359 100644 --- a/src/introspection/FieldObject.cpp +++ b/src/introspection/FieldObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/src/introspection/InputValueObject.cpp b/src/introspection/InputValueObject.cpp index daef5e94..40fa9620 100644 --- a/src/introspection/InputValueObject.cpp +++ b/src/introspection/InputValueObject.cpp @@ -10,7 +10,6 @@ #include #include -#include #include #include diff --git a/src/introspection/IntrospectionSchema.cpp b/src/introspection/IntrospectionSchema.cpp index 048cbcc9..f735c21d 100644 --- a/src/introspection/IntrospectionSchema.cpp +++ b/src/introspection/IntrospectionSchema.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/src/introspection/SchemaObject.cpp b/src/introspection/SchemaObject.cpp index 49199c42..142e39ec 100644 --- a/src/introspection/SchemaObject.cpp +++ b/src/introspection/SchemaObject.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include diff --git a/src/introspection/TypeObject.cpp b/src/introspection/TypeObject.cpp index e7b13ff8..8c1fafce 100644 --- a/src/introspection/TypeObject.cpp +++ b/src/introspection/TypeObject.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include From 79af047030fc3769c1bc9c7b66e01eddb3875362 Mon Sep 17 00:00:00 2001 From: Bill Avery Date: Mon, 16 Sep 2024 22:30:32 -0700 Subject: [PATCH 5/5] fix(fmt): minor fixes following up to last change --- src/GraphQLService.cpp | 2 +- src/Validation.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/GraphQLService.cpp b/src/GraphQLService.cpp index ab84142a..9b704d8b 100644 --- a/src/GraphQLService.cpp +++ b/src/GraphQLService.cpp @@ -1082,7 +1082,7 @@ void SelectionVisitor::visitField(const peg::ast_node& field) catch (const std::exception& ex) { std::promise promise; - auto message = std::format("Field error name: {} unknown error: ", alias, ex.what()); + auto message = std::format("Field error name: {} unknown error: {}", alias, ex.what()); promise.set_exception( std::make_exception_ptr(schema_exception { { schema_error { std::move(message), diff --git a/src/Validation.cpp b/src/Validation.cpp index c560c8b3..a065fad1 100644 --- a/src/Validation.cpp +++ b/src/Validation.cpp @@ -1944,31 +1944,31 @@ void ValidateExecutableVisitor::visitDirectives( switch (location) { case introspection::DirectiveLocation::QUERY: - message += " name: QUERY"; + message += " name: QUERY"sv; break; case introspection::DirectiveLocation::MUTATION: - message += " name: MUTATION"; + message += " name: MUTATION"sv; break; case introspection::DirectiveLocation::SUBSCRIPTION: - message += " name: SUBSCRIPTION"; + message += " name: SUBSCRIPTION"sv; break; case introspection::DirectiveLocation::FIELD: - message += " name: FIELD"; + message += " name: FIELD"sv; break; case introspection::DirectiveLocation::FRAGMENT_DEFINITION: - message += " name: FRAGMENT_DEFINITION"; + message += " name: FRAGMENT_DEFINITION"sv; break; case introspection::DirectiveLocation::FRAGMENT_SPREAD: - message += " name: FRAGMENT_SPREAD"; + message += " name: FRAGMENT_SPREAD"sv; break; case introspection::DirectiveLocation::INLINE_FRAGMENT: - message += " name: INLINE_FRAGMENT"; + message += " name: INLINE_FRAGMENT"sv; break; default: