Skip to content

Commit 5e01ddb

Browse files
authored
Merge pull request #202 from wravery/main
Don't add Variables:: scope to scalar and built-in types in clientgen
2 parents cee3dd4 + 4938f4e commit 5e01ddb

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

samples/client/mutate/MutateClient.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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<bool>::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 == 1, "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+
bool 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
}

src/ClientGenerator.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ static_assert(graphql::internal::MinorVersion == )cpp"
206206
{
207207
pendingSeparator.reset();
208208

209-
headerFile << R"cpp(enum class )cpp" << _schemaLoader.getCppType(enumType->name()) << R"cpp(
209+
headerFile << R"cpp(enum class )cpp" << _schemaLoader.getCppType(enumType->name())
210+
<< R"cpp(
210211
{
211212
)cpp";
212213
for (const auto& enumValue : enumType->enumValues())
@@ -605,8 +606,17 @@ response::Value serializeVariables(Variables&& variables)
605606
for (const auto& variable : variables)
606607
{
607608
sourceFile << R"cpp( result.emplace_back(R"js()cpp" << variable.name
608-
<< R"cpp()js"s, ModifiedVariable<Variables::)cpp"
609-
<< _schemaLoader.getCppType(variable.type->name()) << R"cpp(>::serialize)cpp"
609+
<< R"cpp()js"s, ModifiedVariable<)cpp";
610+
611+
const auto& builtinTypes = _schemaLoader.getBuiltinTypes();
612+
613+
if (builtinTypes.find(variable.type->name()) == builtinTypes.cend()
614+
&& _schemaLoader.getSchemaType(variable.type->name()) != SchemaType::Scalar)
615+
{
616+
sourceFile << R"cpp(Variables::)cpp";
617+
}
618+
619+
sourceFile << _schemaLoader.getCppType(variable.type->name()) << R"cpp(>::serialize)cpp"
610620
<< getTypeModifierList(variable.modifiers)
611621
<< R"cpp((std::move(variables.)cpp" << variable.cppName << R"cpp()));
612622
)cpp";

0 commit comments

Comments
 (0)