@@ -48,9 +48,22 @@ SchemaLoader::SchemaLoader(SchemaOptions&& schemaOptions)
48
48
" message from the parser!" );
49
49
}
50
50
51
+ // Visit all of the definitions in the first pass.
51
52
for (const auto & child : _ast.root ->children )
52
53
{
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
+ }
54
67
}
55
68
56
69
validateSchema ();
@@ -436,6 +449,17 @@ void SchemaLoader::validateImplementedInterfaces() const
436
449
}
437
450
}
438
451
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
+
439
463
void SchemaLoader::visitDefinition (const peg::ast_node& definition)
440
464
{
441
465
if (definition.is_type <peg::schema_definition>())
@@ -450,6 +474,10 @@ void SchemaLoader::visitDefinition(const peg::ast_node& definition)
450
474
{
451
475
visitScalarTypeDefinition (definition);
452
476
}
477
+ else if (definition.is_type <peg::scalar_type_extension>())
478
+ {
479
+ visitScalarTypeExtension (definition);
480
+ }
453
481
else if (definition.is_type <peg::enum_type_definition>())
454
482
{
455
483
visitEnumTypeDefinition (definition);
0 commit comments