Skip to content

Commit 78cfd67

Browse files
authored
Merge pull request #203 from wravery/v3.x
Don't add Variables:: scope to scalar and built-in types in clientgen
2 parents 9313634 + ab4912a commit 78cfd67

File tree

7 files changed

+26
-14
lines changed

7 files changed

+26
-14
lines changed

samples/client/benchmark/BenchmarkClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#include <algorithm>
99
#include <array>
10-
#include <stdexcept>
1110
#include <sstream>
11+
#include <stdexcept>
1212
#include <string_view>
1313

1414
using namespace std::literals;

samples/client/mutate/MutateClient.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#include <algorithm>
99
#include <array>
10-
#include <stdexcept>
1110
#include <sstream>
11+
#include <stdexcept>
1212
#include <string_view>
1313

1414
using namespace std::literals;
@@ -132,14 +132,14 @@ const std::string& GetRequestText() noexcept
132132
# Copyright (c) Microsoft Corporation. All rights reserved.
133133
# Licensed under the MIT License.
134134
135-
mutation CompleteTaskMutation($input: CompleteTaskInput! = {id: "ZmFrZVRhc2tJZA==", isComplete: true, clientMutationId: "Hi There!"}) {
135+
mutation CompleteTaskMutation($input: CompleteTaskInput! = {id: "ZmFrZVRhc2tJZA==", isComplete: true, clientMutationId: "Hi There!"}, $skipClientMutationId: Boolean!) {
136136
completedTask: completeTask(input: $input) {
137137
completedTask: task {
138138
completedTaskId: id
139139
title
140140
isComplete
141141
}
142-
clientMutationId
142+
clientMutationId @skip(if: $skipClientMutationId)
143143
}
144144
}
145145
)gql"s;
@@ -166,6 +166,7 @@ response::Value serializeVariables(Variables&& variables)
166166
response::Value result { response::Type::Map };
167167

168168
result.emplace_back(R"js(input)js"s, ModifiedVariable<Variables::CompleteTaskInput>::serialize(std::move(variables.input)));
169+
result.emplace_back(R"js(skipClientMutationId)js"s, ModifiedVariable<response::BooleanType>::serialize(std::move(variables.skipClientMutationId)));
169170

170171
return result;
171172
}

samples/client/mutate/MutateClient.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ static_assert(graphql::internal::MinorVersion == 7, "regenerate with clientgen:
2929
/// # Copyright (c) Microsoft Corporation. All rights reserved.
3030
/// # Licensed under the MIT License.
3131
///
32-
/// mutation CompleteTaskMutation($input: CompleteTaskInput! = {id: "ZmFrZVRhc2tJZA==", isComplete: true, clientMutationId: "Hi There!"}) {
32+
/// mutation CompleteTaskMutation($input: CompleteTaskInput! = {id: "ZmFrZVRhc2tJZA==", isComplete: true, clientMutationId: "Hi There!"}, $skipClientMutationId: Boolean!) {
3333
/// completedTask: completeTask(input: $input) {
3434
/// completedTask: task {
3535
/// completedTaskId: id
3636
/// title
3737
/// isComplete
3838
/// }
39-
/// clientMutationId
39+
/// clientMutationId @skip(if: $skipClientMutationId)
4040
/// }
4141
/// }
4242
/// </code>
@@ -67,6 +67,7 @@ struct Variables
6767
};
6868

6969
CompleteTaskInput input {};
70+
response::BooleanType skipClientMutationId {};
7071
};
7172

7273
response::Value serializeVariables(Variables&& variables);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4-
mutation CompleteTaskMutation($input: CompleteTaskInput! = {id: "ZmFrZVRhc2tJZA==", isComplete: true, clientMutationId: "Hi There!"}) {
4+
mutation CompleteTaskMutation($input: CompleteTaskInput! = {id: "ZmFrZVRhc2tJZA==", isComplete: true, clientMutationId: "Hi There!"}, $skipClientMutationId: Boolean!) {
55
completedTask: completeTask(input: $input) {
66
completedTask: task {
77
completedTaskId: id
88
title
99
isComplete
1010
}
11-
clientMutationId
11+
clientMutationId @skip(if: $skipClientMutationId)
1212
}
1313
}

samples/client/query/QueryClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#include <algorithm>
99
#include <array>
10-
#include <stdexcept>
1110
#include <sstream>
11+
#include <stdexcept>
1212
#include <string_view>
1313

1414
using namespace std::literals;

samples/client/subscribe/SubscribeClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#include <algorithm>
99
#include <array>
10-
#include <stdexcept>
1110
#include <sstream>
11+
#include <stdexcept>
1212
#include <string_view>
1313

1414
using namespace std::literals;

src/ClientGenerator.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ static_assert(graphql::internal::MinorVersion == )cpp"
223223
{
224224
pendingSeparator.reset();
225225

226-
headerFile << R"cpp(enum class )cpp" << _schemaLoader.getCppType(enumType->name()) << R"cpp(
226+
headerFile << R"cpp(enum class )cpp" << _schemaLoader.getCppType(enumType->name())
227+
<< R"cpp(
227228
{
228229
)cpp";
229230
for (const auto& enumValue : enumType->enumValues())
@@ -451,8 +452,8 @@ bool Generator::outputSource() const noexcept
451452
452453
#include <algorithm>
453454
#include <array>
454-
#include <stdexcept>
455455
#include <sstream>
456+
#include <stdexcept>
456457
#include <string_view>
457458
458459
using namespace std::literals;
@@ -625,8 +626,17 @@ response::Value serializeVariables(Variables&& variables)
625626
for (const auto& variable : variables)
626627
{
627628
sourceFile << R"cpp( result.emplace_back(R"js()cpp" << variable.name
628-
<< R"cpp()js"s, ModifiedVariable<Variables::)cpp"
629-
<< _schemaLoader.getCppType(variable.type->name()) << R"cpp(>::serialize)cpp"
629+
<< R"cpp()js"s, ModifiedVariable<)cpp";
630+
631+
const auto& builtinTypes = _schemaLoader.getBuiltinTypes();
632+
633+
if (builtinTypes.find(variable.type->name()) == builtinTypes.cend()
634+
&& _schemaLoader.getSchemaType(variable.type->name()) != SchemaType::Scalar)
635+
{
636+
sourceFile << R"cpp(Variables::)cpp";
637+
}
638+
639+
sourceFile << _schemaLoader.getCppType(variable.type->name()) << R"cpp(>::serialize)cpp"
630640
<< getTypeModifierList(variable.modifiers)
631641
<< R"cpp((std::move(variables.)cpp" << variable.cppName << R"cpp()));
632642
)cpp";

0 commit comments

Comments
 (0)