@@ -592,6 +592,19 @@ enum class [[nodiscard]] TypeModifier {
592
592
List,
593
593
};
594
594
595
+ // Test if there are any non-None modifiers left.
596
+ template <TypeModifier... Other>
597
+ concept OnlyNoneModifiers = (... && (Other == TypeModifier::None));
598
+
599
+ // Test if the next modifier is Nullable.
600
+ template <TypeModifier Modifier>
601
+ concept NullableModifier = Modifier == TypeModifier::Nullable;
602
+
603
+ // Test if the next modifier is List.
604
+ template <TypeModifier Modifier>
605
+ concept ListModifier = Modifier == TypeModifier::List;
606
+
607
+ // Convert arguments and input types with a non-templated static method.
595
608
template <typename Type>
596
609
struct Argument
597
610
{
@@ -619,18 +632,6 @@ GRAPHQLSERVICE_EXPORT response::Value Argument<response::Value>::convert(
619
632
620
633
namespace {
621
634
622
- // Test if there are any non-None modifiers left.
623
- template <TypeModifier... Other>
624
- concept OnlyNoneModifiers = (... && (Other == TypeModifier::None));
625
-
626
- // Test if the next modifier is Nullable.
627
- template <TypeModifier Modifier>
628
- concept NullableModifier = Modifier == TypeModifier::Nullable;
629
-
630
- // Test if the next modifier is List.
631
- template <TypeModifier Modifier>
632
- concept ListModifier = Modifier == TypeModifier::List;
633
-
634
635
// These types are used as scalar arguments even though they are represented with a class.
635
636
template <typename Type>
636
637
concept ScalarArgumentClass = std::is_same_v<Type, std::string> || std::is_same_v<Type,
@@ -879,14 +880,70 @@ class [[nodiscard]] Object : public std::enable_shared_from_this<Object>
879
880
ResolverMap _resolvers;
880
881
};
881
882
882
- // Test if this Type is Object.
883
- template <typename Type>
884
- concept ObjectType = std::is_same_v<Object, Type>;
885
-
886
883
// Test if this Type inherits from Object.
887
884
template <typename Type>
888
885
concept ObjectBaseType = std::is_base_of_v<Object, Type>;
889
886
887
+ // Convert result types with non-templated static methods.
888
+ template <typename Type>
889
+ struct Result
890
+ {
891
+ using future_type = typename std::conditional_t <ObjectBaseType<Type>,
892
+ AwaitableObject<std::shared_ptr<const Object>>, AwaitableScalar<Type>>;
893
+
894
+ // Convert a single value of the specified type to JSON.
895
+ [[nodiscard]] static AwaitableResolver convert (
896
+ typename future_type result, ResolverParams params);
897
+
898
+ // Validate a single scalar value is the expected type.
899
+ static void validateScalar (const response::Value& value);
900
+ };
901
+
902
+ #ifdef GRAPHQL_DLLEXPORTS
903
+ // Export all of the built-in converters
904
+ template <>
905
+ GRAPHQLSERVICE_EXPORT AwaitableResolver Result<int >::convert(
906
+ AwaitableScalar<int > result, ResolverParams params);
907
+ template <>
908
+ GRAPHQLSERVICE_EXPORT AwaitableResolver Result<double >::convert(
909
+ AwaitableScalar<double > result, ResolverParams params);
910
+ template <>
911
+ GRAPHQLSERVICE_EXPORT AwaitableResolver Result<std::string>::convert(
912
+ AwaitableScalar<std::string> result, ResolverParams params);
913
+ template <>
914
+ GRAPHQLSERVICE_EXPORT AwaitableResolver Result<bool >::convert(
915
+ AwaitableScalar<bool > result, ResolverParams params);
916
+ template <>
917
+ GRAPHQLSERVICE_EXPORT AwaitableResolver Result<response::IdType>::convert(
918
+ AwaitableScalar<response::IdType> result, ResolverParams params);
919
+ template <>
920
+ GRAPHQLSERVICE_EXPORT AwaitableResolver Result<response::Value>::convert(
921
+ AwaitableScalar<response::Value> result, ResolverParams params);
922
+ template <>
923
+ GRAPHQLSERVICE_EXPORT AwaitableResolver Result<Object>::convert(
924
+ AwaitableObject<std::shared_ptr<const Object>> result, ResolverParams params);
925
+
926
+ // Export all of the scalar value validation methods
927
+ template <>
928
+ GRAPHQLSERVICE_EXPORT void Result<int >::validateScalar(const response::Value& value);
929
+ template <>
930
+ GRAPHQLSERVICE_EXPORT void Result<double >::validateScalar(const response::Value& value);
931
+ template <>
932
+ GRAPHQLSERVICE_EXPORT void Result<std::string>::validateScalar(const response::Value& value);
933
+ template <>
934
+ GRAPHQLSERVICE_EXPORT void Result<bool >::validateScalar(const response::Value& value);
935
+ template <>
936
+ GRAPHQLSERVICE_EXPORT void Result<response::IdType>::validateScalar(const response::Value& value);
937
+ template <>
938
+ GRAPHQLSERVICE_EXPORT void Result<response::Value>::validateScalar(const response::Value& value);
939
+ #endif // GRAPHQL_DLLEXPORTS
940
+
941
+ namespace {
942
+
943
+ // Test if this Type is Object.
944
+ template <typename Type>
945
+ concept ObjectType = std::is_same_v<Object, Type>;
946
+
890
947
// Test if this Type inherits from Object but is not Object itself.
891
948
template <typename Type>
892
949
concept ObjectDerivedType = ObjectBaseType<Type> && !ObjectType<Type>;
@@ -944,10 +1001,6 @@ struct ModifiedResult
944
1001
AwaitableObject<std::shared_ptr<const Object>>, AwaitableScalar<type>>;
945
1002
};
946
1003
947
- // Convert a single value of the specified type to JSON.
948
- [[nodiscard]] static AwaitableResolver convert (
949
- typename ResultTraits<Type>::future_type result, ResolverParams params);
950
-
951
1004
// Peel off the none modifier. If it's included, it should always be last in the list.
952
1005
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
953
1006
[[nodiscard]] static inline AwaitableResolver convert (
@@ -962,7 +1015,7 @@ struct ModifiedResult
962
1015
963
1016
co_await params.launch ;
964
1017
965
- auto awaitedResult = co_await ModifiedResult <Object>::convert (
1018
+ auto awaitedResult = co_await Result <Object>::convert (
966
1019
std::static_pointer_cast<const Object>(co_await result),
967
1020
std::move (params));
968
1021
@@ -978,7 +1031,7 @@ struct ModifiedResult
978
1031
static_assert (sizeof ...(Other) == 0 , " None modifier should always be last" );
979
1032
980
1033
// Just call through to the partial specialization without the modifier.
981
- return convert (std::move (result), std::move (params));
1034
+ return Result<Type>:: convert (std::move (result), std::move (params));
982
1035
}
983
1036
984
1037
// Peel off final nullable modifiers for std::shared_ptr of Object and subclasses of Object.
@@ -1012,7 +1065,7 @@ struct ModifiedResult
1012
1065
typename ResultTraits<Type, Modifier, Other...>::type>,
1013
1066
" this is the optional version" );
1014
1067
1015
- if constexpr (!std::is_base_of_v<Object, Type>)
1068
+ if constexpr (!ObjectBaseType< Type>)
1016
1069
{
1017
1070
auto value = result.get_value ();
1018
1071
@@ -1045,7 +1098,7 @@ struct ModifiedResult
1045
1098
typename ResultTraits<Type, Modifier, Other...>::future_type result,
1046
1099
ResolverParams params) requires ListModifier<Modifier>
1047
1100
{
1048
- if constexpr (!std::is_base_of_v<Object, Type>)
1101
+ if constexpr (!ObjectBaseType< Type>)
1049
1102
{
1050
1103
auto value = result.get_value ();
1051
1104
@@ -1141,11 +1194,6 @@ struct ModifiedResult
1141
1194
co_return document;
1142
1195
}
1143
1196
1144
- private
1145
- :
1146
- // Validate a single scalar value is the expected type.
1147
- static void
1148
- validateScalar (const response::Value& value);
1149
1197
// Peel off the none modifier. If it's included, it should always be last in the list.
1150
1198
template <TypeModifier Modifier = TypeModifier::None, TypeModifier... Other>
1151
1199
static inline void validateScalar (
@@ -1154,7 +1202,7 @@ private
1154
1202
static_assert (sizeof ...(Other) == 0 , " None modifier should always be last" );
1155
1203
1156
1204
// Just call through to the partial specialization without the modifier.
1157
- validateScalar (value);
1205
+ Result<Type>:: validateScalar (value);
1158
1206
}
1159
1207
1160
1208
// Peel off nullable modifiers.
@@ -1190,14 +1238,13 @@ private
1190
1238
typename ResultTraits<Type>::future_type result, ResolverParams params,
1191
1239
ResolverCallback&& resolver)
1192
1240
{
1193
- static_assert (!std::is_base_of_v<Object, Type>,
1194
- " ModfiedResult<Object> needs special handling" );
1241
+ static_assert (!ObjectBaseType<Type>, " ModfiedResult<Object> needs special handling" );
1195
1242
1196
1243
auto value = result.get_value ();
1197
1244
1198
1245
if (value)
1199
1246
{
1200
- ModifiedResult ::validateScalar (*value);
1247
+ Result<Type> ::validateScalar (*value);
1201
1248
co_return ResolverResult { response::Value { std::shared_ptr { std::move (value) } } };
1202
1249
}
1203
1250
@@ -1244,47 +1291,7 @@ using IdResult = ModifiedResult<response::IdType>;
1244
1291
using ScalarResult = ModifiedResult<response::Value>;
1245
1292
using ObjectResult = ModifiedResult<Object>;
1246
1293
1247
- #ifdef GRAPHQL_DLLEXPORTS
1248
- // Export all of the built-in converters
1249
- template <>
1250
- GRAPHQLSERVICE_EXPORT AwaitableResolver ModifiedResult<int >::convert(
1251
- AwaitableScalar<int > result, ResolverParams params);
1252
- template <>
1253
- GRAPHQLSERVICE_EXPORT AwaitableResolver ModifiedResult<double >::convert(
1254
- AwaitableScalar<double > result, ResolverParams params);
1255
- template <>
1256
- GRAPHQLSERVICE_EXPORT AwaitableResolver ModifiedResult<std::string>::convert(
1257
- AwaitableScalar<std::string> result, ResolverParams params);
1258
- template <>
1259
- GRAPHQLSERVICE_EXPORT AwaitableResolver ModifiedResult<bool >::convert(
1260
- AwaitableScalar<bool > result, ResolverParams params);
1261
- template <>
1262
- GRAPHQLSERVICE_EXPORT AwaitableResolver ModifiedResult<response::IdType>::convert(
1263
- AwaitableScalar<response::IdType> result, ResolverParams params);
1264
- template <>
1265
- GRAPHQLSERVICE_EXPORT AwaitableResolver ModifiedResult<response::Value>::convert(
1266
- AwaitableScalar<response::Value> result, ResolverParams params);
1267
- template <>
1268
- GRAPHQLSERVICE_EXPORT AwaitableResolver ModifiedResult<Object>::convert(
1269
- AwaitableObject<std::shared_ptr<const Object>> result, ResolverParams params);
1270
-
1271
- // Export all of the scalar value validation methods
1272
- template <>
1273
- GRAPHQLSERVICE_EXPORT void ModifiedResult<int >::validateScalar(const response::Value& value);
1274
- template <>
1275
- GRAPHQLSERVICE_EXPORT void ModifiedResult<double >::validateScalar(const response::Value& value);
1276
- template <>
1277
- GRAPHQLSERVICE_EXPORT void ModifiedResult<std::string>::validateScalar(
1278
- const response::Value& value);
1279
- template <>
1280
- GRAPHQLSERVICE_EXPORT void ModifiedResult<bool >::validateScalar(const response::Value& value);
1281
- template <>
1282
- GRAPHQLSERVICE_EXPORT void ModifiedResult<response::IdType>::validateScalar(
1283
- const response::Value& value);
1284
- template <>
1285
- GRAPHQLSERVICE_EXPORT void ModifiedResult<response::Value>::validateScalar(
1286
- const response::Value& value);
1287
- #endif // GRAPHQL_DLLEXPORTS
1294
+ } // namespace
1288
1295
1289
1296
// Subscription callbacks receive the response::Value representing the result of evaluating the
1290
1297
// SelectionSet against the payload.
0 commit comments