Skip to content

Commit b7d46a1

Browse files
committed
Port input type concepts to GraphQLClient/clientgen
1 parent 7c8b096 commit b7d46a1

File tree

5 files changed

+17
-77
lines changed

5 files changed

+17
-77
lines changed

include/graphqlservice/GraphQLClient.h

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,23 @@ enum class [[nodiscard]] TypeModifier {
7070
List,
7171
};
7272

73-
// Specialized to return true for all INPUT_OBJECT types.
73+
// These types are used as scalar variables even though they are represented with a class.
7474
template <typename Type>
75-
[[nodiscard]] constexpr bool isInputType() noexcept
76-
{
77-
return false;
78-
}
75+
concept ScalarVariableClass = std::is_same_v<Type, std::string> || std::is_same_v<Type,
76+
response::IdType> || std::is_same_v<Type, response::Value>;
7977

80-
// Special-case an innermost nullable INPUT_OBJECT type.
78+
// Any non-scalar class used in a variable is a generated INPUT_OBJECT type.
79+
template <typename Type>
80+
concept InputVariableClass = std::is_class_v<Type> && !ScalarVariableClass<Type>;
81+
82+
// Test if there are any non-None modifiers left.
8183
template <TypeModifier... Other>
82-
[[nodiscard]] constexpr bool onlyNoneModifiers() noexcept
83-
{
84-
return (... && (Other == TypeModifier::None));
85-
}
84+
concept OnlyNoneModifiers = (... && (Other == TypeModifier::None));
85+
86+
// Special-case an innermost nullable INPUT_OBJECT type.
87+
template <typename Type, TypeModifier... Other>
88+
concept InputVariableUniquePtr = InputVariableClass<Type> && OnlyNoneModifiers<Other...>;
89+
8690

8791
// Serialize variable input values with chained type modifiers which add nullable or list wrappers.
8892
template <typename Type>
@@ -94,8 +98,8 @@ struct ModifiedVariable
9498
{
9599
// Peel off modifiers until we get to the underlying type.
96100
using type = typename std::conditional_t<TypeModifier::Nullable == Modifier,
97-
typename std::conditional_t<isInputType<U>() && onlyNoneModifiers<Other...>(),
98-
std::unique_ptr<U>, std::optional<typename VariableTraits<U, Other...>::type>>,
101+
typename std::conditional_t<InputVariableUniquePtr<U, Other...>, std::unique_ptr<U>,
102+
std::optional<typename VariableTraits<U, Other...>::type>>,
99103
typename std::conditional_t<TypeModifier::List == Modifier,
100104
std::vector<typename VariableTraits<U, Other...>::type>, U>>;
101105
};
@@ -173,7 +177,7 @@ struct ModifiedVariable
173177

174178
if (nullableValue)
175179
{
176-
if constexpr (isInputType<Type>() && onlyNoneModifiers<Other...>())
180+
if constexpr (InputVariableUniquePtr<Type, Other...>)
177181
{
178182
// Special case duplicating the std::unique_ptr.
179183
result = std::make_unique<Type>(Type { *nullableValue });

samples/client/multiple/MultipleQueriesClient.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,6 @@ struct [[nodiscard]] CompleteTaskInput
146146

147147
} // namespace multiple
148148

149-
template <>
150-
constexpr bool isInputType<multiple::CompleteTaskInput>() noexcept
151-
{
152-
return true;
153-
}
154-
155149
namespace query::Appointments {
156150

157151
using multiple::GetRequestText;

samples/client/mutate/MutateClient.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,6 @@ struct [[nodiscard]] CompleteTaskInput
7979

8080
} // namespace mutate
8181

82-
template <>
83-
constexpr bool isInputType<mutate::CompleteTaskInput>() noexcept
84-
{
85-
return true;
86-
}
87-
8882
namespace mutation::CompleteTaskMutation {
8983

9084
using mutate::GetRequestText;

samples/client/nestedinput/NestedInputClient.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -108,30 +108,6 @@ struct [[nodiscard]] InputBC
108108

109109
} // namespace nestedinput
110110

111-
template <>
112-
constexpr bool isInputType<nestedinput::InputA>() noexcept
113-
{
114-
return true;
115-
}
116-
117-
template <>
118-
constexpr bool isInputType<nestedinput::InputB>() noexcept
119-
{
120-
return true;
121-
}
122-
123-
template <>
124-
constexpr bool isInputType<nestedinput::InputABCD>() noexcept
125-
{
126-
return true;
127-
}
128-
129-
template <>
130-
constexpr bool isInputType<nestedinput::InputBC>() noexcept
131-
{
132-
return true;
133-
}
134-
135111
namespace query::testQuery {
136112

137113
using nestedinput::GetRequestText;

src/ClientGenerator.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -326,34 +326,6 @@ static_assert(graphql::internal::MinorVersion == )cpp"
326326
schemaNamespaceScope.exit();
327327
pendingSeparator.add();
328328

329-
std::unordered_set<std::string_view> outputIsInputType;
330-
331-
for (const auto& operation : operations)
332-
{
333-
for (const auto& inputType : _requestLoader.getReferencedInputTypes(operation))
334-
{
335-
const auto cppType = _schemaLoader.getCppType(inputType.type->name());
336-
337-
if (!outputIsInputType.insert(cppType).second)
338-
{
339-
continue;
340-
}
341-
342-
pendingSeparator.reset();
343-
344-
headerFile << R"cpp(template <>
345-
constexpr bool isInputType<)cpp"
346-
<< _schemaLoader.getSchemaNamespace() << R"cpp(::)cpp" << cppType
347-
<< R"cpp(>() noexcept
348-
{
349-
return true;
350-
}
351-
)cpp";
352-
353-
pendingSeparator.add();
354-
}
355-
}
356-
357329
for (const auto& operation : operations)
358330
{
359331
pendingSeparator.reset();

0 commit comments

Comments
 (0)