Skip to content

Commit 53dac34

Browse files
committed
Add forward declarations for union types
1 parent 8d1a60f commit 53dac34

File tree

6 files changed

+29
-0
lines changed

6 files changed

+29
-0
lines changed

samples/today/separate/TodaySchema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ namespace object {
6464

6565
class Node;
6666

67+
class UnionType;
68+
6769
class Query;
6870
class PageInfo;
6971
class AppointmentEdge;

samples/today/separate_nointrospection/TodaySchema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ namespace object {
6464

6565
class Node;
6666

67+
class UnionType;
68+
6769
class Query;
6870
class PageInfo;
6971
class AppointmentEdge;

samples/today/unified/TodaySchema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ namespace object {
6464

6565
class Node;
6666

67+
class UnionType;
68+
6769
class Query;
6870
class PageInfo;
6971
class AppointmentEdge;

samples/today/unified_nointrospection/TodaySchema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ namespace object {
6464

6565
class Node;
6666

67+
class UnionType;
68+
6769
class Query;
6870
class PageInfo;
6971
class AppointmentEdge;

samples/validation/schema/ValidationSchema.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ namespace object {
4444
class Sentient;
4545
class Pet;
4646

47+
class CatOrDog;
48+
class DogOrHuman;
49+
class HumanOrAlien;
50+
4751
class Query;
4852
class Dog;
4953
class Alien;

src/SchemaGenerator.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,23 @@ static_assert(graphql::internal::MinorVersion == )cpp"
265265
headerFile << std::endl;
266266
}
267267

268+
if (!_loader.getUnionTypes().empty())
269+
{
270+
if (objectNamespace.enter())
271+
{
272+
headerFile << std::endl;
273+
}
274+
275+
// Forward declare all of the interface types
276+
for (const auto& unionType : _loader.getUnionTypes())
277+
{
278+
headerFile << R"cpp(class )cpp" << unionType.cppType << R"cpp(;
279+
)cpp";
280+
}
281+
282+
headerFile << std::endl;
283+
}
284+
268285
if (!_loader.getObjectTypes().empty())
269286
{
270287
if (_loader.isIntrospection())

0 commit comments

Comments
 (0)