Skip to content

Commit 2c1a677

Browse files
authored
Merge pull request #234 from wravery/more-constexpr-schema
More constexpr schema
2 parents 9afda58 + 6e8d8b3 commit 2c1a677

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+449
-89
lines changed

include/graphqlservice/introspection/IntrospectionSchema.h

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
static_assert(graphql::internal::MajorVersion == 4, "regenerate with schemagen: major version mismatch");
1515
static_assert(graphql::internal::MinorVersion == 2, "regenerate with schemagen: minor version mismatch");
1616

17+
#include <array>
1718
#include <memory>
1819
#include <string>
19-
#include <vector>
20+
#include <string_view>
2021

2122
namespace graphql {
2223
namespace introspection {
@@ -33,6 +34,22 @@ enum class TypeKind
3334
NON_NULL
3435
};
3536

37+
constexpr auto getTypeKindNames() noexcept
38+
{
39+
using namespace std::literals;
40+
41+
return std::array<std::string_view, 8> {
42+
R"gql(SCALAR)gql"sv,
43+
R"gql(OBJECT)gql"sv,
44+
R"gql(INTERFACE)gql"sv,
45+
R"gql(UNION)gql"sv,
46+
R"gql(ENUM)gql"sv,
47+
R"gql(INPUT_OBJECT)gql"sv,
48+
R"gql(LIST)gql"sv,
49+
R"gql(NON_NULL)gql"sv
50+
};
51+
}
52+
3653
enum class DirectiveLocation
3754
{
3855
QUERY,
@@ -56,6 +73,33 @@ enum class DirectiveLocation
5673
INPUT_FIELD_DEFINITION
5774
};
5875

76+
constexpr auto getDirectiveLocationNames() noexcept
77+
{
78+
using namespace std::literals;
79+
80+
return std::array<std::string_view, 19> {
81+
R"gql(QUERY)gql"sv,
82+
R"gql(MUTATION)gql"sv,
83+
R"gql(SUBSCRIPTION)gql"sv,
84+
R"gql(FIELD)gql"sv,
85+
R"gql(FRAGMENT_DEFINITION)gql"sv,
86+
R"gql(FRAGMENT_SPREAD)gql"sv,
87+
R"gql(INLINE_FRAGMENT)gql"sv,
88+
R"gql(VARIABLE_DEFINITION)gql"sv,
89+
R"gql(SCHEMA)gql"sv,
90+
R"gql(SCALAR)gql"sv,
91+
R"gql(OBJECT)gql"sv,
92+
R"gql(FIELD_DEFINITION)gql"sv,
93+
R"gql(ARGUMENT_DEFINITION)gql"sv,
94+
R"gql(INTERFACE)gql"sv,
95+
R"gql(UNION)gql"sv,
96+
R"gql(ENUM)gql"sv,
97+
R"gql(ENUM_VALUE)gql"sv,
98+
R"gql(INPUT_OBJECT)gql"sv,
99+
R"gql(INPUT_FIELD_DEFINITION)gql"sv
100+
};
101+
}
102+
59103
class Schema;
60104
class Type;
61105
class Field;

samples/learn/schema/DroidObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ class Droid final
239239
: Droid { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
240240
{
241241
}
242+
243+
static constexpr std::string_view getObjectType() noexcept
244+
{
245+
return { R"gql(Droid)gql" };
246+
}
242247
};
243248

244249
} // namespace graphql::learn::object

samples/learn/schema/HumanObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ class Human final
239239
: Human { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
240240
{
241241
}
242+
243+
static constexpr std::string_view getObjectType() noexcept
244+
{
245+
return { R"gql(Human)gql" };
246+
}
242247
};
243248

244249
} // namespace graphql::learn::object

samples/learn/schema/MutationObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ class Mutation final
115115
: Mutation { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
116116
{
117117
}
118+
119+
static constexpr std::string_view getObjectType() noexcept
120+
{
121+
return { R"gql(Mutation)gql" };
122+
}
118123
};
119124

120125
} // namespace graphql::learn::object

samples/learn/schema/QueryObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ class Query final
173173
: Query { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
174174
{
175175
}
176+
177+
static constexpr std::string_view getObjectType() noexcept
178+
{
179+
return { R"gql(Query)gql" };
180+
}
176181
};
177182

178183
} // namespace graphql::learn::object

samples/learn/schema/ReviewObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ class Review final
142142
: Review { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
143143
{
144144
}
145+
146+
static constexpr std::string_view getObjectType() noexcept
147+
{
148+
return { R"gql(Review)gql" };
149+
}
145150
};
146151

147152
} // namespace graphql::learn::object

samples/learn/schema/StarWarsSchema.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ using namespace std::literals;
2424
namespace graphql {
2525
namespace service {
2626

27-
static const std::array<std::string_view, 3> s_namesEpisode = {
28-
R"gql(NEW_HOPE)gql"sv,
29-
R"gql(EMPIRE)gql"sv,
30-
R"gql(JEDI)gql"sv
31-
};
27+
static const auto s_namesEpisode = learn::getEpisodeNames();
3228

3329
template <>
3430
learn::Episode ModifiedArgument<learn::Episode>::convert(const response::Value& value)

samples/learn/schema/StarWarsSchema.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
static_assert(graphql::internal::MajorVersion == 4, "regenerate with schemagen: major version mismatch");
1515
static_assert(graphql::internal::MinorVersion == 2, "regenerate with schemagen: minor version mismatch");
1616

17+
#include <array>
1718
#include <memory>
1819
#include <string>
19-
#include <vector>
20+
#include <string_view>
2021

2122
namespace graphql {
2223
namespace learn {
@@ -28,6 +29,17 @@ enum class Episode
2829
JEDI
2930
};
3031

32+
constexpr auto getEpisodeNames() noexcept
33+
{
34+
using namespace std::literals;
35+
36+
return std::array<std::string_view, 3> {
37+
R"gql(NEW_HOPE)gql"sv,
38+
R"gql(EMPIRE)gql"sv,
39+
R"gql(JEDI)gql"sv
40+
};
41+
}
42+
3143
struct ReviewInput
3244
{
3345
int stars {};

samples/today/nointrospection/AppointmentConnectionObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ class AppointmentConnection final
148148
: AppointmentConnection { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
149149
{
150150
}
151+
152+
static constexpr std::string_view getObjectType() noexcept
153+
{
154+
return { R"gql(AppointmentConnection)gql" };
155+
}
151156
};
152157

153158
} // namespace graphql::today::object

samples/today/nointrospection/AppointmentEdgeObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ class AppointmentEdge final
148148
: AppointmentEdge { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
149149
{
150150
}
151+
152+
static constexpr std::string_view getObjectType() noexcept
153+
{
154+
return { R"gql(AppointmentEdge)gql" };
155+
}
151156
};
152157

153158
} // namespace graphql::today::object

samples/today/nointrospection/AppointmentObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ class Appointment final
257257
: Appointment { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
258258
{
259259
}
260+
261+
static constexpr std::string_view getObjectType() noexcept
262+
{
263+
return { R"gql(Appointment)gql" };
264+
}
260265
};
261266

262267
} // namespace graphql::today::object

samples/today/nointrospection/CompleteTaskPayloadObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ class CompleteTaskPayload final
148148
: CompleteTaskPayload { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
149149
{
150150
}
151+
152+
static constexpr std::string_view getObjectType() noexcept
153+
{
154+
return { R"gql(CompleteTaskPayload)gql" };
155+
}
151156
};
152157

153158
} // namespace graphql::today::object

samples/today/nointrospection/ExpensiveObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ class Expensive final
118118
: Expensive { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
119119
{
120120
}
121+
122+
static constexpr std::string_view getObjectType() noexcept
123+
{
124+
return { R"gql(Expensive)gql" };
125+
}
121126
};
122127

123128
} // namespace graphql::today::object

samples/today/nointrospection/FolderConnectionObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ class FolderConnection final
148148
: FolderConnection { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
149149
{
150150
}
151+
152+
static constexpr std::string_view getObjectType() noexcept
153+
{
154+
return { R"gql(FolderConnection)gql" };
155+
}
151156
};
152157

153158
} // namespace graphql::today::object

samples/today/nointrospection/FolderEdgeObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ class FolderEdge final
148148
: FolderEdge { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
149149
{
150150
}
151+
152+
static constexpr std::string_view getObjectType() noexcept
153+
{
154+
return { R"gql(FolderEdge)gql" };
155+
}
151156
};
152157

153158
} // namespace graphql::today::object

samples/today/nointrospection/FolderObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ class Folder final
197197
: Folder { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
198198
{
199199
}
200+
201+
static constexpr std::string_view getObjectType() noexcept
202+
{
203+
return { R"gql(Folder)gql" };
204+
}
200205
};
201206

202207
} // namespace graphql::today::object

samples/today/nointrospection/MutationObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ class Mutation final
148148
: Mutation { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
149149
{
150150
}
151+
152+
static constexpr std::string_view getObjectType() noexcept
153+
{
154+
return { R"gql(Mutation)gql" };
155+
}
151156
};
152157

153158
} // namespace graphql::today::object

samples/today/nointrospection/NestedTypeObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ class NestedType final
148148
: NestedType { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
149149
{
150150
}
151+
152+
static constexpr std::string_view getObjectType() noexcept
153+
{
154+
return { R"gql(NestedType)gql" };
155+
}
151156
};
152157

153158
} // namespace graphql::today::object

samples/today/nointrospection/PageInfoObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ class PageInfo final
148148
: PageInfo { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
149149
{
150150
}
151+
152+
static constexpr std::string_view getObjectType() noexcept
153+
{
154+
return { R"gql(PageInfo)gql" };
155+
}
151156
};
152157

153158
} // namespace graphql::today::object

samples/today/nointrospection/QueryObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,11 @@ class Query final
478478
: Query { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
479479
{
480480
}
481+
482+
static constexpr std::string_view getObjectType() noexcept
483+
{
484+
return { R"gql(Query)gql" };
485+
}
481486
};
482487

483488
} // namespace graphql::today::object

samples/today/nointrospection/SubscriptionObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ class Subscription final
148148
: Subscription { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
149149
{
150150
}
151+
152+
static constexpr std::string_view getObjectType() noexcept
153+
{
154+
return { R"gql(Subscription)gql" };
155+
}
151156
};
152157

153158
} // namespace graphql::today::object

samples/today/nointrospection/TaskConnectionObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ class TaskConnection final
148148
: TaskConnection { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
149149
{
150150
}
151+
152+
static constexpr std::string_view getObjectType() noexcept
153+
{
154+
return { R"gql(TaskConnection)gql" };
155+
}
151156
};
152157

153158
} // namespace graphql::today::object

samples/today/nointrospection/TaskEdgeObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ class TaskEdge final
148148
: TaskEdge { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
149149
{
150150
}
151+
152+
static constexpr std::string_view getObjectType() noexcept
153+
{
154+
return { R"gql(TaskEdge)gql" };
155+
}
151156
};
152157

153158
} // namespace graphql::today::object

samples/today/nointrospection/TaskObject.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ class Task final
197197
: Task { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
198198
{
199199
}
200+
201+
static constexpr std::string_view getObjectType() noexcept
202+
{
203+
return { R"gql(Task)gql" };
204+
}
200205
};
201206

202207
} // namespace graphql::today::object

samples/today/nointrospection/TodaySchema.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ using namespace std::literals;
2525
namespace graphql {
2626
namespace service {
2727

28-
static const std::array<std::string_view, 4> s_namesTaskState = {
29-
R"gql(New)gql"sv,
30-
R"gql(Started)gql"sv,
31-
R"gql(Complete)gql"sv,
32-
R"gql(Unassigned)gql"sv
33-
};
28+
static const auto s_namesTaskState = today::getTaskStateNames();
3429

3530
template <>
3631
today::TaskState ModifiedArgument<today::TaskState>::convert(const response::Value& value)

0 commit comments

Comments
 (0)