Skip to content

Commit dfecf03

Browse files
committed
Declare embedded structs first for better layout
1 parent 634e01f commit dfecf03

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

samples/client/MutateClient.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ enum class TaskState
6464
struct Variables
6565
{
6666
struct CompleteTaskInput
67-
{
67+
{
6868
response::IdType id {};
6969
std::optional<TaskState> testTaskState {};
7070
std::optional<response::BooleanType> isComplete {};
@@ -88,7 +88,6 @@ struct Response
8888
};
8989

9090
std::optional<completedTask_Task> completedTask {};
91-
9291
std::optional<response::StringType> clientMutationId {};
9392
};
9493

samples/client/QueryClient.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ struct Response
127127
std::optional<std::vector<std::optional<edges_AppointmentEdge>>> edges {};
128128
};
129129

130-
appointments_AppointmentConnection appointments {};
131-
132130
struct tasks_TaskConnection
133131
{
134132
struct edges_TaskEdge
@@ -147,8 +145,6 @@ struct Response
147145
std::optional<std::vector<std::optional<edges_TaskEdge>>> edges {};
148146
};
149147

150-
tasks_TaskConnection tasks {};
151-
152148
struct unreadCounts_FolderConnection
153149
{
154150
struct edges_FolderEdge
@@ -167,9 +163,6 @@ struct Response
167163
std::optional<std::vector<std::optional<edges_FolderEdge>>> edges {};
168164
};
169165

170-
unreadCounts_FolderConnection unreadCounts {};
171-
172-
TaskState testTaskState {};
173166
struct anyType_UnionType
174167
{
175168
response::StringType _typename {};
@@ -181,6 +174,10 @@ struct Response
181174
response::BooleanType isNow {};
182175
};
183176

177+
appointments_AppointmentConnection appointments {};
178+
tasks_TaskConnection tasks {};
179+
unreadCounts_FolderConnection unreadCounts {};
180+
TaskState testTaskState {};
184181
std::vector<std::optional<anyType_UnionType>> anyType {};
185182
};
186183

src/ClientGenerator.cpp

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static_assert(graphql::internal::MinorVersion == )cpp"
261261

262262
headerFile << R"cpp( struct )cpp" << _schemaLoader.getCppType(inputType->name())
263263
<< R"cpp(
264-
{
264+
{
265265
)cpp";
266266

267267
for (const auto& inputField : inputType->inputFields())
@@ -314,6 +314,11 @@ response::Value serializeVariables(Variables&& variables);
314314
{
315315
pendingSeparator.add();
316316
}
317+
}
318+
319+
for (const auto& responseField : responseType.fields)
320+
{
321+
pendingSeparator.reset();
317322

318323
headerFile << R"cpp( )cpp"
319324
<< RequestLoader::getOutputCppType(getResponseFieldCppType(responseField),
@@ -401,26 +406,29 @@ bool Generator::outputResponseFieldType(std::ostream& headerFile,
401406
{
402407
pendingSeparator.reset();
403408

404-
if (fieldNames.emplace(field.name).second)
409+
if (fieldNames.emplace(field.name).second
410+
&& outputResponseFieldType(headerFile, field, indent + 1))
405411
{
406-
if (outputResponseFieldType(headerFile, field, indent + 1))
407-
{
408-
pendingSeparator.add();
409-
}
412+
pendingSeparator.add();
413+
}
414+
}
410415

416+
fieldNames.clear();
417+
418+
for (const auto& field : responseField.children)
419+
{
420+
pendingSeparator.reset();
421+
422+
if (fieldNames.emplace(field.name).second)
423+
{
411424
headerFile << indentTabs << R"cpp( )cpp"
412425
<< RequestLoader::getOutputCppType(getResponseFieldCppType(field),
413426
field.modifiers)
414427
<< R"cpp( )cpp" << field.cppName << R"cpp( {};
415-
)cpp";
416-
}
417-
else
418-
{
419-
headerFile << indentTabs << R"cpp( // duplicate: )cpp" << field.cppName
420-
<< R"cpp(
421428
)cpp";
422429
}
423430
}
431+
424432
break;
425433
}
426434

@@ -429,7 +437,6 @@ bool Generator::outputResponseFieldType(std::ostream& headerFile,
429437
}
430438

431439
headerFile << indentTabs << R"cpp(};
432-
433440
)cpp";
434441

435442
return true;
@@ -507,8 +514,8 @@ using namespace )cpp"
507514
if (!variables.empty())
508515
{
509516
sourceFile << R"cpp(template <>
510-
response::Value ModifiedVariable<)cpp" << cppType
511-
<< R"cpp(>::serialize()cpp" << cppType << R"cpp(&& value)
517+
response::Value ModifiedVariable<)cpp"
518+
<< cppType << R"cpp(>::serialize()cpp" << cppType << R"cpp(&& value)
512519
{
513520
response::Value result { response::Type::EnumValue };
514521
@@ -530,8 +537,9 @@ response::Value ModifiedVariable<)cpp" << cppType
530537
const auto cppType = _schemaLoader.getCppType(inputType->name());
531538

532539
sourceFile << R"cpp(template <>
533-
response::Value ModifiedVariable<Variables::)cpp" << cppType
534-
<< R"cpp(>::serialize(Variables::)cpp" << cppType << R"cpp(&& inputValue)
540+
response::Value ModifiedVariable<Variables::)cpp"
541+
<< cppType << R"cpp(>::serialize(Variables::)cpp" << cppType
542+
<< R"cpp(&& inputValue)
535543
{
536544
response::Value result { response::Type::Map };
537545
@@ -565,8 +573,8 @@ response::Value ModifiedVariable<Variables::)cpp" << cppType
565573
const auto cppType = _schemaLoader.getCppType(enumType->name());
566574

567575
sourceFile << R"cpp(template <>
568-
)cpp" << cppType << R"cpp( ModifiedResponse<)cpp" << cppType
569-
<< R"cpp(>::parse(response::Value&& value)
576+
)cpp" << cppType << R"cpp( ModifiedResponse<)cpp"
577+
<< cppType << R"cpp(>::parse(response::Value&& value)
570578
{
571579
if (!value.maybe_enum())
572580
{

0 commit comments

Comments
 (0)