diff --git a/include/graphqlservice/introspection/IntrospectionSchema.h b/include/graphqlservice/introspection/IntrospectionSchema.h index 3ea811b0..b39fe13f 100644 --- a/include/graphqlservice/introspection/IntrospectionSchema.h +++ b/include/graphqlservice/introspection/IntrospectionSchema.h @@ -11,6 +11,7 @@ #include "graphqlservice/GraphQLResponse.h" #include "graphqlservice/GraphQLService.h" +#include "graphqlservice/internal/DllExports.h" #include "graphqlservice/internal/Version.h" #include "graphqlservice/internal/Schema.h" @@ -25,8 +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 { +namespace graphql::introspection { class Schema; class Type; class Field; @@ -54,33 +54,6 @@ void AddDirectiveDetails(const std::shared_ptr& typeDirectiv GRAPHQLSERVICE_EXPORT void AddTypesToSchema(const std::shared_ptr& schema); -} // namespace introspection - -namespace service { - -#ifdef GRAPHQL_DLLEXPORTS -// Export all of the built-in converters -template <> -GRAPHQLSERVICE_EXPORT introspection::TypeKind Argument::convert( - const response::Value& value); -template <> -GRAPHQLSERVICE_EXPORT AwaitableResolver Result::convert( - AwaitableScalar result, ResolverParams&& params); -template <> -GRAPHQLSERVICE_EXPORT void Result::validateScalar( - const response::Value& value); -template <> -GRAPHQLSERVICE_EXPORT introspection::DirectiveLocation Argument::convert( - const response::Value& value); -template <> -GRAPHQLSERVICE_EXPORT AwaitableResolver Result::convert( - AwaitableScalar result, ResolverParams&& params); -template <> -GRAPHQLSERVICE_EXPORT void Result::validateScalar( - const response::Value& value); -#endif // GRAPHQL_DLLEXPORTS - -} // namespace service -} // namespace graphql +} // namespace graphql::introspection #endif // INTROSPECTIONSCHEMA_H diff --git a/include/graphqlservice/introspection/IntrospectionSharedTypes.h b/include/graphqlservice/introspection/IntrospectionSharedTypes.h index 63b71c2c..9e1d5acb 100644 --- a/include/graphqlservice/introspection/IntrospectionSharedTypes.h +++ b/include/graphqlservice/introspection/IntrospectionSharedTypes.h @@ -10,6 +10,7 @@ #include "graphqlservice/GraphQLResponse.h" +#include "graphqlservice/internal/DllExports.h" #include "graphqlservice/internal/Version.h" #include @@ -23,7 +24,8 @@ 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::introspection { +namespace graphql { +namespace introspection { enum class TypeKind { @@ -146,6 +148,33 @@ enum class DirectiveLocation }; } -} // namespace graphql::introspection +} // namespace introspection + +namespace service { + +#ifdef GRAPHQL_DLLEXPORTS +// Export all of the built-in converters +template <> +GRAPHQLSERVICE_EXPORT introspection::TypeKind Argument::convert( + const response::Value& value); +template <> +GRAPHQLSERVICE_EXPORT AwaitableResolver Result::convert( + AwaitableScalar result, ResolverParams&& params); +template <> +GRAPHQLSERVICE_EXPORT void Result::validateScalar( + const response::Value& value); +template <> +GRAPHQLSERVICE_EXPORT introspection::DirectiveLocation Argument::convert( + const response::Value& value); +template <> +GRAPHQLSERVICE_EXPORT AwaitableResolver Result::convert( + AwaitableScalar result, ResolverParams&& params); +template <> +GRAPHQLSERVICE_EXPORT void Result::validateScalar( + const response::Value& value); +#endif // GRAPHQL_DLLEXPORTS + +} // namespace service +} // namespace graphql #endif // INTROSPECTIONSHAREDTYPES_H diff --git a/samples/learn/schema/StarWarsSchema.h b/samples/learn/schema/StarWarsSchema.h index 5182070f..9529c7ec 100644 --- a/samples/learn/schema/StarWarsSchema.h +++ b/samples/learn/schema/StarWarsSchema.h @@ -25,8 +25,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 learn { +namespace graphql::learn { namespace object { class Character; @@ -73,7 +72,6 @@ void AddSubscriptionDetails(const std::shared_ptr& typeSubsc std::shared_ptr GetSchema(); -} // namespace learn -} // namespace graphql +} // namespace graphql::learn #endif // STARWARSSCHEMA_H diff --git a/samples/learn/schema/StarWarsSharedTypes.h b/samples/learn/schema/StarWarsSharedTypes.h index 007c2b19..b9dee9da 100644 --- a/samples/learn/schema/StarWarsSharedTypes.h +++ b/samples/learn/schema/StarWarsSharedTypes.h @@ -23,7 +23,8 @@ 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::learn { +namespace graphql { +namespace learn { enum class [[nodiscard("unnecessary conversion")]] Episode { @@ -71,6 +72,7 @@ struct [[nodiscard("unnecessary construction")]] ReviewInput std::optional commentary; }; -} // namespace graphql::learn +} // namespace learn +} // namespace graphql #endif // STARWARSSHAREDTYPES_H diff --git a/samples/proxy/schema/ProxySchema.h b/samples/proxy/schema/ProxySchema.h index 1fd0922f..bbaa0e6c 100644 --- a/samples/proxy/schema/ProxySchema.h +++ b/samples/proxy/schema/ProxySchema.h @@ -25,8 +25,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 proxy { +namespace graphql::proxy { namespace object { class Query; @@ -57,7 +56,6 @@ void AddQueryResultsDetails(const std::shared_ptr& typeQuery std::shared_ptr GetSchema(); -} // namespace proxy -} // namespace graphql +} // namespace graphql::proxy #endif // PROXYSCHEMA_H diff --git a/samples/proxy/schema/ProxySharedTypes.h b/samples/proxy/schema/ProxySharedTypes.h index 48f821a2..56ec1fa1 100644 --- a/samples/proxy/schema/ProxySharedTypes.h +++ b/samples/proxy/schema/ProxySharedTypes.h @@ -23,7 +23,8 @@ 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::proxy { +namespace graphql { +namespace proxy { enum class [[nodiscard("unnecessary conversion")]] OperationType { @@ -75,6 +76,7 @@ struct [[nodiscard("unnecessary construction")]] QueryInput std::optional variables; }; -} // namespace graphql::proxy +} // namespace proxy +} // namespace graphql #endif // PROXYSHAREDTYPES_H diff --git a/samples/today/nointrospection/TodaySchema.h b/samples/today/nointrospection/TodaySchema.h index 594c9264..80b99eee 100644 --- a/samples/today/nointrospection/TodaySchema.h +++ b/samples/today/nointrospection/TodaySchema.h @@ -25,8 +25,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 today { +namespace graphql::today { namespace object { class Node; @@ -97,7 +96,6 @@ void AddExpensiveDetails(const std::shared_ptr& typeExpensiv std::shared_ptr GetSchema(); -} // namespace today -} // namespace graphql +} // namespace graphql::today #endif // TODAYSCHEMA_H diff --git a/samples/today/nointrospection/TodaySharedTypes.h b/samples/today/nointrospection/TodaySharedTypes.h index 39774106..b3c7b086 100644 --- a/samples/today/nointrospection/TodaySharedTypes.h +++ b/samples/today/nointrospection/TodaySharedTypes.h @@ -23,7 +23,8 @@ 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::today { +namespace graphql { +namespace today { enum class [[nodiscard("unnecessary conversion")]] TaskState { @@ -232,6 +233,7 @@ struct [[nodiscard("unnecessary construction")]] FirstNestedInput ThirdNestedInput third; }; -} // namespace graphql::today +} // namespace today +} // namespace graphql #endif // TODAYSHAREDTYPES_H diff --git a/samples/today/schema/TodaySchema.h b/samples/today/schema/TodaySchema.h index 594c9264..80b99eee 100644 --- a/samples/today/schema/TodaySchema.h +++ b/samples/today/schema/TodaySchema.h @@ -25,8 +25,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 today { +namespace graphql::today { namespace object { class Node; @@ -97,7 +96,6 @@ void AddExpensiveDetails(const std::shared_ptr& typeExpensiv std::shared_ptr GetSchema(); -} // namespace today -} // namespace graphql +} // namespace graphql::today #endif // TODAYSCHEMA_H diff --git a/samples/today/schema/TodaySharedTypes.h b/samples/today/schema/TodaySharedTypes.h index 39774106..b3c7b086 100644 --- a/samples/today/schema/TodaySharedTypes.h +++ b/samples/today/schema/TodaySharedTypes.h @@ -23,7 +23,8 @@ 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::today { +namespace graphql { +namespace today { enum class [[nodiscard("unnecessary conversion")]] TaskState { @@ -232,6 +233,7 @@ struct [[nodiscard("unnecessary construction")]] FirstNestedInput ThirdNestedInput third; }; -} // namespace graphql::today +} // namespace today +} // namespace graphql #endif // TODAYSHAREDTYPES_H diff --git a/samples/validation/schema/ValidationSchema.h b/samples/validation/schema/ValidationSchema.h index 0d6a6041..80d071f7 100644 --- a/samples/validation/schema/ValidationSchema.h +++ b/samples/validation/schema/ValidationSchema.h @@ -25,8 +25,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 validation { +namespace graphql::validation { namespace object { class Sentient; @@ -95,7 +94,6 @@ void AddArgumentsDetails(const std::shared_ptr& typeArgument std::shared_ptr GetSchema(); -} // namespace validation -} // namespace graphql +} // namespace graphql::validation #endif // VALIDATIONSCHEMA_H diff --git a/samples/validation/schema/ValidationSharedTypes.h b/samples/validation/schema/ValidationSharedTypes.h index 71aa4da4..7b963d0a 100644 --- a/samples/validation/schema/ValidationSharedTypes.h +++ b/samples/validation/schema/ValidationSharedTypes.h @@ -23,7 +23,8 @@ 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::validation { +namespace graphql { +namespace validation { enum class [[nodiscard("unnecessary conversion")]] DogCommand { @@ -94,6 +95,7 @@ struct [[nodiscard("unnecessary construction")]] ComplexInput std::optional owner; }; -} // namespace graphql::validation +} // namespace validation +} // namespace graphql #endif // VALIDATIONSHAREDTYPES_H diff --git a/src/SchemaGenerator.cpp b/src/SchemaGenerator.cpp index ccf5b518..1a62684a 100644 --- a/src/SchemaGenerator.cpp +++ b/src/SchemaGenerator.cpp @@ -174,7 +174,15 @@ bool Generator::outputSchemaHeader() const noexcept headerFile << R"cpp(#include "graphqlservice/GraphQLResponse.h" #include "graphqlservice/GraphQLService.h" -#include "graphqlservice/internal/Version.h" +)cpp"; + + if (_loader.isIntrospection()) + { + headerFile << R"cpp(#include "graphqlservice/internal/DllExports.h" +)cpp"; + } + + headerFile << R"cpp(#include "graphqlservice/internal/Version.h" #include "graphqlservice/internal/Schema.h" )cpp"; @@ -204,8 +212,8 @@ static_assert(graphql::internal::MinorVersion == )cpp" )cpp"; - NamespaceScope graphqlNamespace { headerFile, "graphql" }; - NamespaceScope schemaNamespace { headerFile, _loader.getSchemaNamespace() }; + const auto schemaNamespace = std::format(R"cpp(graphql::{})cpp", _loader.getSchemaNamespace()); + NamespaceScope schemaNamespaceScope { headerFile, schemaNamespace }; NamespaceScope objectNamespace { headerFile, "object", true }; PendingBlankLine pendingSeparator { headerFile }; @@ -449,66 +457,12 @@ static_assert(graphql::internal::MinorVersion == )cpp" headerFile << std::endl; } - NamespaceScope serviceNamespace { headerFile, "service", true }; - if (_loader.isIntrospection()) { headerFile << R"cpp(GRAPHQLSERVICE_EXPORT void AddTypesToSchema(const std::shared_ptr& schema); )cpp"; - - if (!_loader.getEnumTypes().empty() || !_loader.getInputTypes().empty()) - { - if (schemaNamespace.exit()) - { - headerFile << std::endl; - } - - serviceNamespace.enter(); - - headerFile << R"cpp( -#ifdef GRAPHQL_DLLEXPORTS -// Export all of the built-in converters -)cpp"; - - for (const auto& enumType : _loader.getEnumTypes()) - { - headerFile << R"cpp(template <> -GRAPHQLSERVICE_EXPORT )cpp" << _loader.getSchemaNamespace() - << R"cpp(::)cpp" << enumType.cppType << R"cpp( Argument<)cpp" - << _loader.getSchemaNamespace() << R"cpp(::)cpp" << enumType.cppType - << R"cpp(>::convert( - const response::Value& value); -template <> -GRAPHQLSERVICE_EXPORT AwaitableResolver Result<)cpp" - << _loader.getSchemaNamespace() << R"cpp(::)cpp" << enumType.cppType - << R"cpp(>::convert( - AwaitableScalar<)cpp" << _loader.getSchemaNamespace() - << R"cpp(::)cpp" << enumType.cppType - << R"cpp(> result, ResolverParams&& params); -template <> -GRAPHQLSERVICE_EXPORT void Result<)cpp" - << _loader.getSchemaNamespace() << R"cpp(::)cpp" << enumType.cppType - << R"cpp(>::validateScalar( - const response::Value& value); -)cpp"; - } - - for (const auto& inputType : _loader.getInputTypes()) - { - headerFile << R"cpp(template <> -GRAPHQLSERVICE_EXPORT )cpp" << _loader.getSchemaNamespace() - << R"cpp(::)cpp" << inputType.cppType << R"cpp( Argument<)cpp" - << inputType.cppType << R"cpp(>::convert( - const response::Value& value); -)cpp"; - } - - headerFile << R"cpp(#endif // GRAPHQL_DLLEXPORTS - -)cpp"; - } } else { @@ -673,7 +627,15 @@ bool Generator::outputSharedTypesHeader() const noexcept headerFile << R"cpp(#include "graphqlservice/GraphQLResponse.h" -#include "graphqlservice/internal/Version.h" +)cpp"; + + if (_loader.isIntrospection()) + { + headerFile << R"cpp(#include "graphqlservice/internal/DllExports.h" +)cpp"; + } + + headerFile << R"cpp(#include "graphqlservice/internal/Version.h" #include #include @@ -694,8 +656,8 @@ static_assert(graphql::internal::MinorVersion == )cpp" )cpp"; - const auto schemaNamespace = std::format(R"cpp(graphql::{})cpp", _loader.getSchemaNamespace()); - NamespaceScope schemaNamespaceScope { headerFile, schemaNamespace }; + NamespaceScope graphqlNamespace { headerFile, "graphql" }; + NamespaceScope schemaNamespace { headerFile, _loader.getSchemaNamespace() }; PendingBlankLine pendingSeparator { headerFile }; if (!_loader.getEnumTypes().empty()) @@ -901,6 +863,60 @@ static_assert(graphql::internal::MinorVersion == )cpp" } } + if (_loader.isIntrospection()) + { + if (schemaNamespace.exit()) + { + pendingSeparator.add(); + } + + pendingSeparator.reset(); + + NamespaceScope serviceNamespace { headerFile, "service" }; + + headerFile << R"cpp( +#ifdef GRAPHQL_DLLEXPORTS +// Export all of the built-in converters +)cpp"; + + for (const auto& enumType : _loader.getEnumTypes()) + { + headerFile << R"cpp(template <> +GRAPHQLSERVICE_EXPORT )cpp" + << _loader.getSchemaNamespace() << R"cpp(::)cpp" << enumType.cppType + << R"cpp( Argument<)cpp" << _loader.getSchemaNamespace() << R"cpp(::)cpp" + << enumType.cppType << R"cpp(>::convert( + const response::Value& value); +template <> +GRAPHQLSERVICE_EXPORT AwaitableResolver Result<)cpp" + << _loader.getSchemaNamespace() << R"cpp(::)cpp" << enumType.cppType + << R"cpp(>::convert( + AwaitableScalar<)cpp" + << _loader.getSchemaNamespace() << R"cpp(::)cpp" << enumType.cppType + << R"cpp(> result, ResolverParams&& params); +template <> +GRAPHQLSERVICE_EXPORT void Result<)cpp" + << _loader.getSchemaNamespace() << R"cpp(::)cpp" << enumType.cppType + << R"cpp(>::validateScalar( + const response::Value& value); +)cpp"; + } + + for (const auto& inputType : _loader.getInputTypes()) + { + headerFile << R"cpp(template <> +GRAPHQLSERVICE_EXPORT )cpp" + << _loader.getSchemaNamespace() << R"cpp(::)cpp" << inputType.cppType + << R"cpp( Argument<)cpp" << inputType.cppType << R"cpp(>::convert( + const response::Value& value); +)cpp"; + } + + headerFile << R"cpp(#endif // GRAPHQL_DLLEXPORTS + +)cpp"; + } + return true; } @@ -2275,9 +2291,8 @@ Operations::Operations()cpp"; { bool firstValue = true; - sourceFile << R"cpp( static const auto s_names)cpp" - << enumType.cppType << R"cpp( = get)cpp" << enumType.cppType - << R"cpp(Names(); + sourceFile << R"cpp( static const auto s_names)cpp" << enumType.cppType + << R"cpp( = get)cpp" << enumType.cppType << R"cpp(Names(); type)cpp" << enumType.cppType << R"cpp(->AddEnumValues({ )cpp"; diff --git a/src/introspection/IntrospectionSchema.h b/src/introspection/IntrospectionSchema.h index 3ea811b0..b39fe13f 100644 --- a/src/introspection/IntrospectionSchema.h +++ b/src/introspection/IntrospectionSchema.h @@ -11,6 +11,7 @@ #include "graphqlservice/GraphQLResponse.h" #include "graphqlservice/GraphQLService.h" +#include "graphqlservice/internal/DllExports.h" #include "graphqlservice/internal/Version.h" #include "graphqlservice/internal/Schema.h" @@ -25,8 +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 { +namespace graphql::introspection { class Schema; class Type; class Field; @@ -54,33 +54,6 @@ void AddDirectiveDetails(const std::shared_ptr& typeDirectiv GRAPHQLSERVICE_EXPORT void AddTypesToSchema(const std::shared_ptr& schema); -} // namespace introspection - -namespace service { - -#ifdef GRAPHQL_DLLEXPORTS -// Export all of the built-in converters -template <> -GRAPHQLSERVICE_EXPORT introspection::TypeKind Argument::convert( - const response::Value& value); -template <> -GRAPHQLSERVICE_EXPORT AwaitableResolver Result::convert( - AwaitableScalar result, ResolverParams&& params); -template <> -GRAPHQLSERVICE_EXPORT void Result::validateScalar( - const response::Value& value); -template <> -GRAPHQLSERVICE_EXPORT introspection::DirectiveLocation Argument::convert( - const response::Value& value); -template <> -GRAPHQLSERVICE_EXPORT AwaitableResolver Result::convert( - AwaitableScalar result, ResolverParams&& params); -template <> -GRAPHQLSERVICE_EXPORT void Result::validateScalar( - const response::Value& value); -#endif // GRAPHQL_DLLEXPORTS - -} // namespace service -} // namespace graphql +} // namespace graphql::introspection #endif // INTROSPECTIONSCHEMA_H diff --git a/src/introspection/IntrospectionSharedTypes.h b/src/introspection/IntrospectionSharedTypes.h index 63b71c2c..9e1d5acb 100644 --- a/src/introspection/IntrospectionSharedTypes.h +++ b/src/introspection/IntrospectionSharedTypes.h @@ -10,6 +10,7 @@ #include "graphqlservice/GraphQLResponse.h" +#include "graphqlservice/internal/DllExports.h" #include "graphqlservice/internal/Version.h" #include @@ -23,7 +24,8 @@ 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::introspection { +namespace graphql { +namespace introspection { enum class TypeKind { @@ -146,6 +148,33 @@ enum class DirectiveLocation }; } -} // namespace graphql::introspection +} // namespace introspection + +namespace service { + +#ifdef GRAPHQL_DLLEXPORTS +// Export all of the built-in converters +template <> +GRAPHQLSERVICE_EXPORT introspection::TypeKind Argument::convert( + const response::Value& value); +template <> +GRAPHQLSERVICE_EXPORT AwaitableResolver Result::convert( + AwaitableScalar result, ResolverParams&& params); +template <> +GRAPHQLSERVICE_EXPORT void Result::validateScalar( + const response::Value& value); +template <> +GRAPHQLSERVICE_EXPORT introspection::DirectiveLocation Argument::convert( + const response::Value& value); +template <> +GRAPHQLSERVICE_EXPORT AwaitableResolver Result::convert( + AwaitableScalar result, ResolverParams&& params); +template <> +GRAPHQLSERVICE_EXPORT void Result::validateScalar( + const response::Value& value); +#endif // GRAPHQL_DLLEXPORTS + +} // namespace service +} // namespace graphql #endif // INTROSPECTIONSHAREDTYPES_H