Skip to content

Commit

Permalink
Merge pull request #322 from wravery/next
Browse files Browse the repository at this point in the history
fix: #321
  • Loading branch information
wravery authored Sep 24, 2024
2 parents 4d54be8 + 2dc6ebe commit 7426833
Show file tree
Hide file tree
Showing 52 changed files with 4,274 additions and 3,564 deletions.
5 changes: 4 additions & 1 deletion cmake/cppgraphqlgen-update-schema-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ foreach(OLD_FILE ${OLD_FILES})
file(REMOVE "${SCHEMA_SOURCE_DIR}/${OLD_FILE}")
elseif(NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}Schema.h" AND
NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}Schema.ixx" AND
NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}Schema.cpp")
NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}Schema.cpp" AND
NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}SharedTypes.h" AND
NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}SharedTypes.ixx" AND
NOT OLD_FILE STREQUAL "${SCHEMA_PREFIX}SharedTypes.cpp")
message(WARNING "Unexpected file in ${SCHEMA_TARGET} GraphQL schema sources: ${OLD_FILE}")
endif()
endif()
Expand Down
29 changes: 19 additions & 10 deletions include/SchemaGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,17 @@ class [[nodiscard("unnecessary construction")]] Generator
private:
[[nodiscard("unnecessary memory copy")]] std::string getHeaderDir() const noexcept;
[[nodiscard("unnecessary memory copy")]] std::string getSourceDir() const noexcept;
[[nodiscard("unnecessary memory copy")]] std::string getHeaderPath() const noexcept;
[[nodiscard("unnecessary memory copy")]] std::string getModulePath() const noexcept;
[[nodiscard("unnecessary memory copy")]] std::string getSourcePath() const noexcept;

[[nodiscard("unnecessary call")]] bool outputHeader() const noexcept;
[[nodiscard("unnecessary call")]] bool outputModule() const noexcept;
[[nodiscard("unnecessary memory copy")]] std::string getSchemaHeaderPath() const noexcept;
[[nodiscard("unnecessary memory copy")]] std::string getSchemaModulePath() const noexcept;
[[nodiscard("unnecessary memory copy")]] std::string getSchemaSourcePath() const noexcept;
[[nodiscard("unnecessary memory copy")]] std::string getSharedTypesHeaderPath() const noexcept;
[[nodiscard("unnecessary memory copy")]] std::string getSharedTypesModulePath() const noexcept;
[[nodiscard("unnecessary memory copy")]] std::string getSharedTypesSourcePath() const noexcept;

[[nodiscard("unnecessary call")]] bool outputSchemaHeader() const noexcept;
[[nodiscard("unnecessary call")]] bool outputSchemaModule() const noexcept;
[[nodiscard("unnecessary call")]] bool outputSharedTypesHeader() const noexcept;
[[nodiscard("unnecessary call")]] bool outputSharedTypesModule() const noexcept;
void outputInterfaceDeclaration(std::ostream& headerFile, std::string_view cppType) const;
void outputObjectModule(
std::ostream& moduleFile, std::string_view objectNamespace, std::string_view cppType) const;
Expand All @@ -58,7 +63,8 @@ class [[nodiscard("unnecessary construction")]] Generator
[[nodiscard("unnecessary memory copy")]] std::string getResolverDeclaration(
const OutputField& outputField) const noexcept;

[[nodiscard("unnecessary call")]] bool outputSource() const noexcept;
[[nodiscard("unnecessary call")]] bool outputSchemaSource() const noexcept;
[[nodiscard("unnecessary call")]] bool outputSharedTypesSource() const noexcept;
void outputInterfaceImplementation(std::ostream& sourceFile, std::string_view cppType) const;
void outputInterfaceIntrospection(
std::ostream& sourceFile, const InterfaceType& interfaceType) const;
Expand Down Expand Up @@ -94,9 +100,12 @@ class [[nodiscard("unnecessary construction")]] Generator
const std::string _headerDir;
const std::string _moduleDir;
const std::string _sourceDir;
const std::string _headerPath;
const std::string _modulePath;
const std::string _sourcePath;
const std::string _schemaHeaderPath;
const std::string _schemaModulePath;
const std::string _schemaSourcePath;
const std::string _sharedTypesHeaderPath;
const std::string _sharedTypesModulePath;
const std::string _sharedTypesSourcePath;
};

} // namespace graphql::generator::schema
Expand Down
157 changes: 5 additions & 152 deletions include/graphqlservice/introspection/IntrospectionSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@
#include "graphqlservice/GraphQLResponse.h"
#include "graphqlservice/GraphQLService.h"

#include "graphqlservice/internal/DllExports.h"
#include "graphqlservice/internal/Version.h"
#include "graphqlservice/internal/Schema.h"

#include "IntrospectionSharedTypes.h"

#include <array>
#include <memory>
#include <string>
Expand All @@ -23,130 +26,7 @@
static_assert(graphql::internal::MajorVersion == 5, "regenerate with schemagen: major version mismatch");
static_assert(graphql::internal::MinorVersion == 0, "regenerate with schemagen: minor version mismatch");

namespace graphql {
namespace introspection {

enum class TypeKind
{
SCALAR,
OBJECT,
INTERFACE,
UNION,
ENUM,
INPUT_OBJECT,
LIST,
NON_NULL
};

[[nodiscard("unnecessary call")]] 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
};
}

[[nodiscard("unnecessary call")]] constexpr auto getTypeKindValues() noexcept
{
using namespace std::literals;

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

enum class DirectiveLocation
{
QUERY,
MUTATION,
SUBSCRIPTION,
FIELD,
FRAGMENT_DEFINITION,
FRAGMENT_SPREAD,
INLINE_FRAGMENT,
VARIABLE_DEFINITION,
SCHEMA,
SCALAR,
OBJECT,
FIELD_DEFINITION,
ARGUMENT_DEFINITION,
INTERFACE,
UNION,
ENUM,
ENUM_VALUE,
INPUT_OBJECT,
INPUT_FIELD_DEFINITION
};

[[nodiscard("unnecessary call")]] 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
};
}

[[nodiscard("unnecessary call")]] constexpr auto getDirectiveLocationValues() noexcept
{
using namespace std::literals;

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

namespace graphql::introspection {
class Schema;
class Type;
class Field;
Expand Down Expand Up @@ -174,33 +54,6 @@ void AddDirectiveDetails(const std::shared_ptr<schema::ObjectType>& typeDirectiv

GRAPHQLSERVICE_EXPORT void AddTypesToSchema(const std::shared_ptr<schema::Schema>& schema);

} // namespace introspection

namespace service {

#ifdef GRAPHQL_DLLEXPORTS
// Export all of the built-in converters
template <>
GRAPHQLSERVICE_EXPORT introspection::TypeKind Argument<introspection::TypeKind>::convert(
const response::Value& value);
template <>
GRAPHQLSERVICE_EXPORT AwaitableResolver Result<introspection::TypeKind>::convert(
AwaitableScalar<introspection::TypeKind> result, ResolverParams&& params);
template <>
GRAPHQLSERVICE_EXPORT void Result<introspection::TypeKind>::validateScalar(
const response::Value& value);
template <>
GRAPHQLSERVICE_EXPORT introspection::DirectiveLocation Argument<introspection::DirectiveLocation>::convert(
const response::Value& value);
template <>
GRAPHQLSERVICE_EXPORT AwaitableResolver Result<introspection::DirectiveLocation>::convert(
AwaitableScalar<introspection::DirectiveLocation> result, ResolverParams&& params);
template <>
GRAPHQLSERVICE_EXPORT void Result<introspection::DirectiveLocation>::validateScalar(
const response::Value& value);
#endif // GRAPHQL_DLLEXPORTS

} // namespace service
} // namespace graphql
} // namespace graphql::introspection

#endif // INTROSPECTIONSCHEMA_H
10 changes: 2 additions & 8 deletions include/graphqlservice/introspection/IntrospectionSchema.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module;

export module GraphQL.Introspection.IntrospectionSchema;

export import GraphQL.Introspection.IntrospectionSharedTypes;

export import GraphQL.Introspection.SchemaObject;
export import GraphQL.Introspection.TypeObject;
export import GraphQL.Introspection.FieldObject;
Expand All @@ -18,14 +20,6 @@ export import GraphQL.Introspection.DirectiveObject;

export namespace graphql::introspection {

using introspection::TypeKind;
using introspection::getTypeKindNames;
using introspection::getTypeKindValues;

using introspection::DirectiveLocation;
using introspection::getDirectiveLocationNames;
using introspection::getDirectiveLocationValues;

using introspection::AddSchemaDetails;
using introspection::AddTypeDetails;
using introspection::AddFieldDetails;
Expand Down
Loading

0 comments on commit 7426833

Please sign in to comment.