Skip to content

Commit c40381b

Browse files
committed
Handle out-of-order definitions and extensions in the schema doc
1 parent 6cde86b commit c40381b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

include/SchemaLoader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,8 @@ class SchemaLoader
264264
std::string getOutputCppType(const OutputField& field) const noexcept;
265265

266266
private:
267+
static bool isExtension(const peg::ast_node& definition) noexcept;
268+
267269
void visitDefinition(const peg::ast_node& definition);
268270

269271
void visitSchemaDefinition(const peg::ast_node& schemaDefinition);

src/SchemaLoader.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,22 @@ SchemaLoader::SchemaLoader(SchemaOptions&& schemaOptions)
4848
"message from the parser!");
4949
}
5050

51+
// Visit all of the definitions in the first pass.
5152
for (const auto& child : _ast.root->children)
5253
{
53-
visitDefinition(*child);
54+
if (!isExtension(*child))
55+
{
56+
visitDefinition(*child);
57+
}
58+
}
59+
60+
// Visit all of the extensions in a second pass.
61+
for (const auto& child : _ast.root->children)
62+
{
63+
if (isExtension(*child))
64+
{
65+
visitDefinition(*child);
66+
}
5467
}
5568

5669
validateSchema();
@@ -436,6 +449,17 @@ void SchemaLoader::validateImplementedInterfaces() const
436449
}
437450
}
438451

452+
bool SchemaLoader::isExtension(const peg::ast_node& definition) noexcept
453+
{
454+
return definition.is_type<peg::schema_extension>()
455+
|| definition.is_type<peg::scalar_type_extension>()
456+
|| definition.is_type<peg::enum_type_extension>()
457+
|| definition.is_type<peg::input_object_type_extension>()
458+
|| definition.is_type<peg::union_type_extension>()
459+
|| definition.is_type<peg::interface_type_extension>()
460+
|| definition.is_type<peg::object_type_extension>();
461+
}
462+
439463
void SchemaLoader::visitDefinition(const peg::ast_node& definition)
440464
{
441465
if (definition.is_type<peg::schema_definition>())
@@ -450,6 +474,10 @@ void SchemaLoader::visitDefinition(const peg::ast_node& definition)
450474
{
451475
visitScalarTypeDefinition(definition);
452476
}
477+
else if (definition.is_type<peg::scalar_type_extension>())
478+
{
479+
visitScalarTypeExtension(definition);
480+
}
453481
else if (definition.is_type<peg::enum_type_definition>())
454482
{
455483
visitEnumTypeDefinition(definition);

0 commit comments

Comments
 (0)