Skip to content

Commit 4858dc5

Browse files
committed
Forward declare object types earlier
1 parent c68c141 commit 4858dc5

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

SchemaGenerator.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,25 @@ struct )cpp" << inputType.type << R"cpp(
13001300

13011301
if (!_interfaceTypes.empty())
13021302
{
1303+
if (!_objectTypes.empty())
1304+
{
1305+
headerFile << R"cpp(
1306+
namespace object {
1307+
)cpp";
1308+
1309+
// Forward declare all of the object types so the interface types can reference them
1310+
for (const auto& objectType : _objectTypes)
1311+
{
1312+
headerFile << R"cpp(
1313+
class )cpp" << objectType.type << R"cpp(;)cpp";
1314+
}
1315+
1316+
headerFile << R"cpp(
1317+
1318+
} /* namespace object */
1319+
)cpp";
1320+
}
1321+
13031322
// Forward declare all of the interface types
13041323
if (_interfaceTypes.size() > 1)
13051324
{
@@ -1337,9 +1356,11 @@ struct )cpp" << interfaceType.type << R"cpp(
13371356
headerFile << R"cpp(namespace object {
13381357
)cpp";
13391358

1340-
if (_objectTypes.size() > 1)
1359+
if (_interfaceTypes.empty()
1360+
&& _objectTypes.size() > 1)
13411361
{
1342-
// Forward declare all of the object types
1362+
// Forward declare all of the object types if there were no interfaces so the
1363+
// object types can reference one another
13431364
for (const auto& objectType : _objectTypes)
13441365
{
13451366
headerFile << R"cpp(

samples/TodaySchema.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ struct CompleteTaskInput
3434
std::unique_ptr<response::StringType> clientMutationId;
3535
};
3636

37-
struct Node
38-
{
39-
virtual std::future<std::vector<uint8_t>> getId(service::FieldParams&& params) const = 0;
40-
};
41-
4237
namespace object {
4338

4439
class Query;
@@ -57,6 +52,15 @@ class Task;
5752
class Folder;
5853
class NestedType;
5954

55+
} /* namespace object */
56+
57+
struct Node
58+
{
59+
virtual std::future<std::vector<uint8_t>> getId(service::FieldParams&& params) const = 0;
60+
};
61+
62+
namespace object {
63+
6064
class Query
6165
: public service::Object
6266
{

0 commit comments

Comments
 (0)