|
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 |
0 commit comments