| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,7 +54,8 @@ foreach(OLD_FILE ${OLD_FILES}) | |||
| 54 | 54 | NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}Schema.ixx" AND | |
| 55 | 55 | NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}Schema.cpp" AND | |
| 56 | 56 | NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}SharedTypes.h" AND | |
| 57 | - NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}SharedTypes.ixx") | ||
| 57 | + NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}SharedTypes.ixx" AND | ||
| 58 | + NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}SharedTypes.cpp") | ||
| 58 | 59 | message(WARNING "Unexpected file in ${SCHEMA_TARGET} GraphQL schema sources: ${OLD_FILE}") | |
| 59 | 60 | endif() | |
| 60 | 61 | endif() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,9 +40,10 @@ class [[nodiscard("unnecessary construction")]] Generator | |||
| 40 | 40 | [[nodiscard("unnecessary memory copy")]] std::string getSourceDir() const noexcept; | |
| 41 | 41 | [[nodiscard("unnecessary memory copy")]] std::string getSchemaHeaderPath() const noexcept; | |
| 42 | 42 | [[nodiscard("unnecessary memory copy")]] std::string getSchemaModulePath() const noexcept; | |
| 43 | + [[nodiscard("unnecessary memory copy")]] std::string getSchemaSourcePath() const noexcept; | ||
| 43 | 44 | [[nodiscard("unnecessary memory copy")]] std::string getSharedTypesHeaderPath() const noexcept; | |
| 44 | 45 | [[nodiscard("unnecessary memory copy")]] std::string getSharedTypesModulePath() const noexcept; | |
| 45 | - [[nodiscard("unnecessary memory copy")]] std::string getSourcePath() const noexcept; | ||
| 46 | + [[nodiscard("unnecessary memory copy")]] std::string getSharedTypesSourcePath() const noexcept; | ||
| 46 | 47 | ||
| 47 | 48 | [[nodiscard("unnecessary call")]] bool outputSchemaHeader() const noexcept; | |
| 48 | 49 | [[nodiscard("unnecessary call")]] bool outputSchemaModule() const noexcept; | |
@@ -62,7 +63,8 @@ class [[nodiscard("unnecessary construction")]] Generator | |||
| 62 | 63 | [[nodiscard("unnecessary memory copy")]] std::string getResolverDeclaration( | |
| 63 | 64 | const OutputField& outputField) const noexcept; | |
| 64 | 65 | ||
| 65 | - [[nodiscard("unnecessary call")]] bool outputSource() const noexcept; | ||
| 66 | + [[nodiscard("unnecessary call")]] bool outputSchemaSource() const noexcept; | ||
| 67 | + [[nodiscard("unnecessary call")]] bool outputSharedTypesSource() const noexcept; | ||
| 66 | 68 | void outputInterfaceImplementation(std::ostream& sourceFile, std::string_view cppType) const; | |
| 67 | 69 | void outputInterfaceIntrospection( | |
| 68 | 70 | std::ostream& sourceFile, const InterfaceType& interfaceType) const; | |
@@ -100,9 +102,10 @@ class [[nodiscard("unnecessary construction")]] Generator | |||
| 100 | 102 | const std::string _sourceDir; | |
| 101 | 103 | const std::string _schemaHeaderPath; | |
| 102 | 104 | const std::string _schemaModulePath; | |
| 105 | + const std::string _schemaSourcePath; | ||
| 103 | 106 | const std::string _sharedTypesHeaderPath; | |
| 104 | 107 | const std::string _sharedTypesModulePath; | |
| 105 | - const std::string _sourcePath; | ||
| 108 | + const std::string _sharedTypesSourcePath; | ||
| 106 | 109 | }; | |
| 107 | 110 | ||
| 108 | 111 | } // namespace graphql::generator::schema | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,129 +22,7 @@ | |||
| 22 | 22 | ||
| 23 | 23 | using namespace std::literals; | |
| 24 | 24 | ||
| 25 | - namespace graphql { | ||
| 26 | - namespace service { | ||
| 27 | - | ||
| 28 | - static const auto s_namesEpisode = learn::getEpisodeNames(); | ||
| 29 | - static const auto s_valuesEpisode = learn::getEpisodeValues(); | ||
| 30 | - | ||
| 31 | - template <> | ||
| 32 | - learn::Episode Argument<learn::Episode>::convert(const response::Value& value) | ||
| 33 | - { | ||
| 34 | - if (!value.maybe_enum()) | ||
| 35 | - { | ||
| 36 | - throw service::schema_exception { { R"ex(not a valid Episode value)ex" } }; | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | - const auto result = internal::sorted_map_lookup<internal::shorter_or_less>( | ||
| 40 | - s_valuesEpisode, | ||
| 41 | - std::string_view { value.get<std::string>() }); | ||
| 42 | - | ||
| 43 | - if (!result) | ||
| 44 | - { | ||
| 45 | - throw service::schema_exception { { R"ex(not a valid Episode value)ex" } }; | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - return *result; | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - template <> | ||
| 52 | - service::AwaitableResolver Result<learn::Episode>::convert(service::AwaitableScalar<learn::Episode> result, ResolverParams&& params) | ||
| 53 | - { | ||
| 54 | - return ModifiedResult<learn::Episode>::resolve(std::move(result), std::move(params), | ||
| 55 | - [](learn::Episode value, const ResolverParams&) | ||
| 56 | - { | ||
| 57 | - response::Value resolvedResult(response::Type::EnumValue); | ||
| 58 | - | ||
| 59 | - resolvedResult.set<std::string>(std::string { s_namesEpisode[static_cast<std::size_t>(value)] }); | ||
| 60 | - | ||
| 61 | - return resolvedResult; | ||
| 62 | - }); | ||
| 63 | - } | ||
| 64 | - | ||
| 65 | - template <> | ||
| 66 | - void Result<learn::Episode>::validateScalar(const response::Value& value) | ||
| 67 | - { | ||
| 68 | - if (!value.maybe_enum()) | ||
| 69 | - { | ||
| 70 | - throw service::schema_exception { { R"ex(not a valid Episode value)ex" } }; | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - const auto [itr, itrEnd] = internal::sorted_map_equal_range<internal::shorter_or_less>( | ||
| 74 | - s_valuesEpisode.begin(), | ||
| 75 | - s_valuesEpisode.end(), | ||
| 76 | - std::string_view { value.get<std::string>() }); | ||
| 77 | - | ||
| 78 | - if (itr == itrEnd) | ||
| 79 | - { | ||
| 80 | - throw service::schema_exception { { R"ex(not a valid Episode value)ex" } }; | ||
| 81 | - } | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - template <> | ||
| 85 | - learn::ReviewInput Argument<learn::ReviewInput>::convert(const response::Value& value) | ||
| 86 | - { | ||
| 87 | - auto valueStars = service::ModifiedArgument<int>::require("stars", value); | ||
| 88 | - auto valueCommentary = service::ModifiedArgument<std::string>::require<service::TypeModifier::Nullable>("commentary", value); | ||
| 89 | - | ||
| 90 | - return learn::ReviewInput { | ||
| 91 | - valueStars, | ||
| 92 | - std::move(valueCommentary) | ||
| 93 | - }; | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - } // namespace service | ||
| 97 | - | ||
| 98 | - namespace learn { | ||
| 99 | - | ||
| 100 | - ReviewInput::ReviewInput() noexcept | ||
| 101 | - : stars {} | ||
| 102 | - , commentary {} | ||
| 103 | - { | ||
| 104 | - // Explicit definition to prevent ODR violations when LTO is enabled. | ||
| 105 | - } | ||
| 106 | - | ||
| 107 | - ReviewInput::ReviewInput( | ||
| 108 | - int starsArg, | ||
| 109 | - std::optional<std::string> commentaryArg) noexcept | ||
| 110 | - : stars { std::move(starsArg) } | ||
| 111 | - , commentary { std::move(commentaryArg) } | ||
| 112 | - { | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - ReviewInput::ReviewInput(const ReviewInput& other) | ||
| 116 | - : stars { service::ModifiedArgument<int>::duplicate(other.stars) } | ||
| 117 | - , commentary { service::ModifiedArgument<std::string>::duplicate<service::TypeModifier::Nullable>(other.commentary) } | ||
| 118 | - { | ||
| 119 | - } | ||
| 120 | - | ||
| 121 | - ReviewInput::ReviewInput(ReviewInput&& other) noexcept | ||
| 122 | - : stars { std::move(other.stars) } | ||
| 123 | - , commentary { std::move(other.commentary) } | ||
| 124 | - { | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - ReviewInput::~ReviewInput() | ||
| 128 | - { | ||
| 129 | - // Explicit definition to prevent ODR violations when LTO is enabled. | ||
| 130 | - } | ||
| 131 | - | ||
| 132 | - ReviewInput& ReviewInput::operator=(const ReviewInput& other) | ||
| 133 | - { | ||
| 134 | - ReviewInput value { other }; | ||
| 135 | - | ||
| 136 | - std::swap(*this, value); | ||
| 137 | - | ||
| 138 | - return *this; | ||
| 139 | - } | ||
| 140 | - | ||
| 141 | - ReviewInput& ReviewInput::operator=(ReviewInput&& other) noexcept | ||
| 142 | - { | ||
| 143 | - stars = std::move(other.stars); | ||
| 144 | - commentary = std::move(other.commentary); | ||
| 145 | - | ||
| 146 | - return *this; | ||
| 147 | - } | ||
| 25 | + namespace graphql::learn { | ||
| 148 | 26 | ||
| 149 | 27 | Operations::Operations(std::shared_ptr<object::Query> query, std::shared_ptr<object::Mutation> mutation, std::shared_ptr<object::Subscription> subscription) | |
| 150 | 28 | : service::Request({ | |
@@ -179,10 +57,12 @@ void AddTypesToSchema(const std::shared_ptr<schema::Schema>& schema) | |||
| 179 | 57 | auto typeSubscription = schema::ObjectType::Make(R"gql(Subscription)gql"sv, R"md()md"sv); | |
| 180 | 58 | schema->AddType(R"gql(Subscription)gql"sv, typeSubscription); | |
| 181 | 59 | ||
| 60 | + | ||
| 61 | + static const auto s_namesEpisode = getEpisodeNames(); | ||
| 182 | 62 | typeEpisode->AddEnumValues({ | |
| 183 | - { service::s_namesEpisode[static_cast<std::size_t>(learn::Episode::NEW_HOPE)], R"md()md"sv, std::nullopt }, | ||
| 184 | - { service::s_namesEpisode[static_cast<std::size_t>(learn::Episode::EMPIRE)], R"md()md"sv, std::nullopt }, | ||
| 185 | - { service::s_namesEpisode[static_cast<std::size_t>(learn::Episode::JEDI)], R"md()md"sv, std::nullopt } | ||
| 63 | + { s_namesEpisode[static_cast<std::size_t>(learn::Episode::NEW_HOPE)], R"md()md"sv, std::nullopt }, | ||
| 64 | + { s_namesEpisode[static_cast<std::size_t>(learn::Episode::EMPIRE)], R"md()md"sv, std::nullopt }, | ||
| 65 | + { s_namesEpisode[static_cast<std::size_t>(learn::Episode::JEDI)], R"md()md"sv, std::nullopt } | ||
| 186 | 66 | }); | |
| 187 | 67 | ||
| 188 | 68 | typeReviewInput->AddInputValues({ | |
@@ -220,5 +100,4 @@ std::shared_ptr<schema::Schema> GetSchema() | |||
| 220 | 100 | return schema; | |
| 221 | 101 | } | |
| 222 | 102 | ||
| 223 | - } // namespace learn | ||
| 224 | - } // namespace graphql | ||
| 103 | + } // namespace graphql::learn | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,146 @@ | |||
| 1 | + // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| 2 | + // Licensed under the MIT License. | ||
| 3 | + | ||
| 4 | + // WARNING! Do not edit this file manually, your changes will be overwritten. | ||
| 5 | + | ||
| 6 | + #include "graphqlservice/GraphQLService.h" | ||
| 7 | + | ||
| 8 | + #include "StarWarsSharedTypes.h" | ||
| 9 | + | ||
| 10 | + #include <algorithm> | ||
| 11 | + #include <array> | ||
| 12 | + #include <cstddef> | ||
| 13 | + #include <functional> | ||
| 14 | + #include <stdexcept> | ||
| 15 | + #include <string_view> | ||
| 16 | + #include <utility> | ||
| 17 | + #include <vector> | ||
| 18 | + | ||
| 19 | + using namespace std::literals; | ||
| 20 | + | ||
| 21 | + namespace graphql { | ||
| 22 | + namespace service { | ||
| 23 | + | ||
| 24 | + static const auto s_namesEpisode = learn::getEpisodeNames(); | ||
| 25 | + static const auto s_valuesEpisode = learn::getEpisodeValues(); | ||
| 26 | + | ||
| 27 | + template <> | ||
| 28 | + learn::Episode Argument<learn::Episode>::convert(const response::Value& value) | ||
| 29 | + { | ||
| 30 | + if (!value.maybe_enum()) | ||
| 31 | + { | ||
| 32 | + throw service::schema_exception { { R"ex(not a valid Episode value)ex" } }; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + const auto result = internal::sorted_map_lookup<internal::shorter_or_less>( | ||
| 36 | + s_valuesEpisode, | ||
| 37 | + std::string_view { value.get<std::string>() }); | ||
| 38 | + | ||
| 39 | + if (!result) | ||
| 40 | + { | ||
| 41 | + throw service::schema_exception { { R"ex(not a valid Episode value)ex" } }; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + return *result; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + template <> | ||
| 48 | + service::AwaitableResolver Result<learn::Episode>::convert(service::AwaitableScalar<learn::Episode> result, ResolverParams&& params) | ||
| 49 | + { | ||
| 50 | + return ModifiedResult<learn::Episode>::resolve(std::move(result), std::move(params), | ||
| 51 | + [](learn::Episode value, const ResolverParams&) | ||
| 52 | + { | ||
| 53 | + response::Value resolvedResult(response::Type::EnumValue); | ||
| 54 | + | ||
| 55 | + resolvedResult.set<std::string>(std::string { s_namesEpisode[static_cast<std::size_t>(value)] }); | ||
| 56 | + | ||
| 57 | + return resolvedResult; | ||
| 58 | + }); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + template <> | ||
| 62 | + void Result<learn::Episode>::validateScalar(const response::Value& value) | ||
| 63 | + { | ||
| 64 | + if (!value.maybe_enum()) | ||
| 65 | + { | ||
| 66 | + throw service::schema_exception { { R"ex(not a valid Episode value)ex" } }; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + const auto [itr, itrEnd] = internal::sorted_map_equal_range<internal::shorter_or_less>( | ||
| 70 | + s_valuesEpisode.begin(), | ||
| 71 | + s_valuesEpisode.end(), | ||
| 72 | + std::string_view { value.get<std::string>() }); | ||
| 73 | + | ||
| 74 | + if (itr == itrEnd) | ||
| 75 | + { | ||
| 76 | + throw service::schema_exception { { R"ex(not a valid Episode value)ex" } }; | ||
| 77 | + } | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + template <> | ||
| 81 | + learn::ReviewInput Argument<learn::ReviewInput>::convert(const response::Value& value) | ||
| 82 | + { | ||
| 83 | + auto valueStars = service::ModifiedArgument<int>::require("stars", value); | ||
| 84 | + auto valueCommentary = service::ModifiedArgument<std::string>::require<service::TypeModifier::Nullable>("commentary", value); | ||
| 85 | + | ||
| 86 | + return learn::ReviewInput { | ||
| 87 | + valueStars, | ||
| 88 | + std::move(valueCommentary) | ||
| 89 | + }; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + } // namespace service | ||
| 93 | + | ||
| 94 | + namespace learn { | ||
| 95 | + | ||
| 96 | + ReviewInput::ReviewInput() noexcept | ||
| 97 | + : stars {} | ||
| 98 | + , commentary {} | ||
| 99 | + { | ||
| 100 | + // Explicit definition to prevent ODR violations when LTO is enabled. | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + ReviewInput::ReviewInput( | ||
| 104 | + int starsArg, | ||
| 105 | + std::optional<std::string> commentaryArg) noexcept | ||
| 106 | + : stars { std::move(starsArg) } | ||
| 107 | + , commentary { std::move(commentaryArg) } | ||
| 108 | + { | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + ReviewInput::ReviewInput(const ReviewInput& other) | ||
| 112 | + : stars { service::ModifiedArgument<int>::duplicate(other.stars) } | ||
| 113 | + , commentary { service::ModifiedArgument<std::string>::duplicate<service::TypeModifier::Nullable>(other.commentary) } | ||
| 114 | + { | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + ReviewInput::ReviewInput(ReviewInput&& other) noexcept | ||
| 118 | + : stars { std::move(other.stars) } | ||
| 119 | + , commentary { std::move(other.commentary) } | ||
| 120 | + { | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + ReviewInput::~ReviewInput() | ||
| 124 | + { | ||
| 125 | + // Explicit definition to prevent ODR violations when LTO is enabled. | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + ReviewInput& ReviewInput::operator=(const ReviewInput& other) | ||
| 129 | + { | ||
| 130 | + ReviewInput value { other }; | ||
| 131 | + | ||
| 132 | + std::swap(*this, value); | ||
| 133 | + | ||
| 134 | + return *this; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + ReviewInput& ReviewInput::operator=(ReviewInput&& other) noexcept | ||
| 138 | + { | ||
| 139 | + stars = std::move(other.stars); | ||
| 140 | + commentary = std::move(other.commentary); | ||
| 141 | + | ||
| 142 | + return *this; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + } // namespace learn | ||
| 146 | + } // namespace graphql | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,4 @@ | |||
| 1 | + StarWarsSharedTypes.cpp | ||
| 1 | 2 | StarWarsSchema.cpp | |
| 2 | 3 | CharacterObject.cpp | |
| 3 | 4 | HumanObject.cpp | |
| Back | FazBrowse Home | New Git URL |
0 commit comments