Skip to content

More constexpr schema #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion include/graphqlservice/introspection/IntrospectionSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
static_assert(graphql::internal::MajorVersion == 4, "regenerate with schemagen: major version mismatch");
static_assert(graphql::internal::MinorVersion == 2, "regenerate with schemagen: minor version mismatch");

#include <array>
#include <memory>
#include <string>
#include <vector>
#include <string_view>

namespace graphql {
namespace introspection {
Expand All @@ -33,6 +34,22 @@ enum class TypeKind
NON_NULL
};

constexpr auto getTypeKindNames() noexcept
{
using namespace std::literals;

return std::array<std::string_view, 8> {
R"gql(SCALAR)gql"sv,
R"gql(OBJECT)gql"sv,
R"gql(INTERFACE)gql"sv,
R"gql(UNION)gql"sv,
R"gql(ENUM)gql"sv,
R"gql(INPUT_OBJECT)gql"sv,
R"gql(LIST)gql"sv,
R"gql(NON_NULL)gql"sv
};
}

enum class DirectiveLocation
{
QUERY,
Expand All @@ -56,6 +73,33 @@ enum class DirectiveLocation
INPUT_FIELD_DEFINITION
};

constexpr auto getDirectiveLocationNames() noexcept
{
using namespace std::literals;

return std::array<std::string_view, 19> {
R"gql(QUERY)gql"sv,
R"gql(MUTATION)gql"sv,
R"gql(SUBSCRIPTION)gql"sv,
R"gql(FIELD)gql"sv,
R"gql(FRAGMENT_DEFINITION)gql"sv,
R"gql(FRAGMENT_SPREAD)gql"sv,
R"gql(INLINE_FRAGMENT)gql"sv,
R"gql(VARIABLE_DEFINITION)gql"sv,
R"gql(SCHEMA)gql"sv,
R"gql(SCALAR)gql"sv,
R"gql(OBJECT)gql"sv,
R"gql(FIELD_DEFINITION)gql"sv,
R"gql(ARGUMENT_DEFINITION)gql"sv,
R"gql(INTERFACE)gql"sv,
R"gql(UNION)gql"sv,
R"gql(ENUM)gql"sv,
R"gql(ENUM_VALUE)gql"sv,
R"gql(INPUT_OBJECT)gql"sv,
R"gql(INPUT_FIELD_DEFINITION)gql"sv
};
}

class Schema;
class Type;
class Field;
Expand Down
5 changes: 5 additions & 0 deletions samples/learn/schema/DroidObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ class Droid final
: Droid { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(Droid)gql" };
}
};

} // namespace graphql::learn::object
Expand Down
5 changes: 5 additions & 0 deletions samples/learn/schema/HumanObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ class Human final
: Human { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(Human)gql" };
}
};

} // namespace graphql::learn::object
Expand Down
5 changes: 5 additions & 0 deletions samples/learn/schema/MutationObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class Mutation final
: Mutation { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(Mutation)gql" };
}
};

} // namespace graphql::learn::object
Expand Down
5 changes: 5 additions & 0 deletions samples/learn/schema/QueryObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ class Query final
: Query { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(Query)gql" };
}
};

} // namespace graphql::learn::object
Expand Down
5 changes: 5 additions & 0 deletions samples/learn/schema/ReviewObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ class Review final
: Review { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(Review)gql" };
}
};

} // namespace graphql::learn::object
Expand Down
6 changes: 1 addition & 5 deletions samples/learn/schema/StarWarsSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ using namespace std::literals;
namespace graphql {
namespace service {

static const std::array<std::string_view, 3> s_namesEpisode = {
R"gql(NEW_HOPE)gql"sv,
R"gql(EMPIRE)gql"sv,
R"gql(JEDI)gql"sv
};
static const auto s_namesEpisode = learn::getEpisodeNames();

template <>
learn::Episode ModifiedArgument<learn::Episode>::convert(const response::Value& value)
Expand Down
14 changes: 13 additions & 1 deletion samples/learn/schema/StarWarsSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
static_assert(graphql::internal::MajorVersion == 4, "regenerate with schemagen: major version mismatch");
static_assert(graphql::internal::MinorVersion == 2, "regenerate with schemagen: minor version mismatch");

#include <array>
#include <memory>
#include <string>
#include <vector>
#include <string_view>

namespace graphql {
namespace learn {
Expand All @@ -28,6 +29,17 @@ enum class Episode
JEDI
};

constexpr auto getEpisodeNames() noexcept
{
using namespace std::literals;

return std::array<std::string_view, 3> {
R"gql(NEW_HOPE)gql"sv,
R"gql(EMPIRE)gql"sv,
R"gql(JEDI)gql"sv
};
}

struct ReviewInput
{
int stars {};
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/AppointmentConnectionObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class AppointmentConnection final
: AppointmentConnection { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(AppointmentConnection)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/AppointmentEdgeObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class AppointmentEdge final
: AppointmentEdge { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(AppointmentEdge)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/AppointmentObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ class Appointment final
: Appointment { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(Appointment)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/CompleteTaskPayloadObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class CompleteTaskPayload final
: CompleteTaskPayload { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(CompleteTaskPayload)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/ExpensiveObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ class Expensive final
: Expensive { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(Expensive)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/FolderConnectionObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class FolderConnection final
: FolderConnection { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(FolderConnection)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/FolderEdgeObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class FolderEdge final
: FolderEdge { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(FolderEdge)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/FolderObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ class Folder final
: Folder { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(Folder)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/MutationObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class Mutation final
: Mutation { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(Mutation)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/NestedTypeObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class NestedType final
: NestedType { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(NestedType)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/PageInfoObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class PageInfo final
: PageInfo { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(PageInfo)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/QueryObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ class Query final
: Query { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(Query)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/SubscriptionObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class Subscription final
: Subscription { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(Subscription)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/TaskConnectionObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class TaskConnection final
: TaskConnection { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(TaskConnection)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/TaskEdgeObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ class TaskEdge final
: TaskEdge { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(TaskEdge)gql" };
}
};

} // namespace graphql::today::object
Expand Down
5 changes: 5 additions & 0 deletions samples/today/nointrospection/TaskObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ class Task final
: Task { std::unique_ptr<const Concept> { std::make_unique<Model<T>>(std::move(pimpl)) } }
{
}

static constexpr std::string_view getObjectType() noexcept
{
return { R"gql(Task)gql" };
}
};

} // namespace graphql::today::object
Expand Down
7 changes: 1 addition & 6 deletions samples/today/nointrospection/TodaySchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ using namespace std::literals;
namespace graphql {
namespace service {

static const std::array<std::string_view, 4> s_namesTaskState = {
R"gql(New)gql"sv,
R"gql(Started)gql"sv,
R"gql(Complete)gql"sv,
R"gql(Unassigned)gql"sv
};
static const auto s_namesTaskState = today::getTaskStateNames();

template <>
today::TaskState ModifiedArgument<today::TaskState>::convert(const response::Value& value)
Expand Down
Loading