Skip to content

Commit 024c298

Browse files
Constexpr elements for type reflection
1 parent eef8bcc commit 024c298

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/SchemaGenerator.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ static_assert(graphql::internal::MinorVersion == )cpp"
146146
}
147147
}
148148

149+
headerFile << R"cpp(
150+
151+
using namespace std::literals;
152+
153+
)cpp";
154+
149155
if (!_loader.getEnumTypes().empty())
150156
{
151157
pendingSeparator.reset();
@@ -173,6 +179,30 @@ static_assert(graphql::internal::MinorVersion == )cpp"
173179
};
174180
175181
)cpp";
182+
firstValue = true;
183+
184+
headerFile << R"cpp(constexpr std::array<std::string_view, )cpp"
185+
<< enumType.values.size() << R"cpp(> namesArray)cpp" << enumType.cppType
186+
<< R"cpp( = {
187+
)cpp";
188+
189+
for (const auto& value : enumType.values)
190+
{
191+
if (!firstValue)
192+
{
193+
headerFile << R"cpp(,
194+
)cpp";
195+
}
196+
197+
firstValue = false;
198+
headerFile << R"cpp( R"gql()cpp" << value.value << R"cpp()gql"sv)cpp";
199+
}
200+
201+
headerFile << R"cpp(
202+
};
203+
204+
)cpp";
205+
176206
}
177207
}
178208

@@ -964,6 +994,10 @@ void Generator::outputObjectDeclaration(
964994
<< R"cpp( service::TypeNames getTypeNames() const noexcept;
965995
service::ResolverMap getResolvers() const noexcept;
966996
997+
constexpr static std::string_view static_typename = std::string_view(
998+
")cpp" << objectType.type << R"cpp("
999+
);
1000+
9671001
void beginSelectionSet(const service::SelectionSetParams& params) const final;
9681002
void endSelectionSet(const service::SelectionSetParams& params) const final;
9691003

0 commit comments

Comments
 (0)