@@ -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+
439463void 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