Skip to content

Commit c549cc4

Browse files
committed
Fix #44 - Handle schema extensions
1 parent c53afe9 commit c549cc4

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

GraphQLTree.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,12 @@ struct ast_selector<schema_extension>
525525
{
526526
};
527527

528+
template <>
529+
struct ast_selector<operation_type_definition>
530+
: std::true_type
531+
{
532+
};
533+
528534
template <>
529535
struct ast_selector<scalar_type_extension>
530536
: std::true_type

SchemaGenerator.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,14 @@ bool Generator::fixupInputFieldList(InputFieldList& fields)
316316

317317
void Generator::visitDefinition(const peg::ast_node& definition)
318318
{
319-
if (definition.is<peg::schema_definition>()
320-
|| definition.is<peg::schema_extension>())
319+
if (definition.is<peg::schema_definition>())
321320
{
322321
visitSchemaDefinition(definition);
323322
}
323+
else if (definition.is<peg::schema_extension>())
324+
{
325+
visitSchemaExtension(definition);
326+
}
324327
else if (definition.is<peg::scalar_type_definition>())
325328
{
326329
visitScalarTypeDefinition(definition);
@@ -383,6 +386,18 @@ void Generator::visitSchemaDefinition(const peg::ast_node& schemaDefinition)
383386
});
384387
}
385388

389+
void Generator::visitSchemaExtension(const peg::ast_node& schemaExtension)
390+
{
391+
peg::for_each_child<peg::operation_type_definition>(schemaExtension,
392+
[this](const peg::ast_node & child)
393+
{
394+
std::string operation(child.children.front()->content());
395+
std::string name(child.children.back()->content());
396+
397+
_operationTypes.push_back({ std::move(name), std::move(operation) });
398+
});
399+
}
400+
386401
void Generator::visitObjectTypeDefinition(const peg::ast_node& objectTypeDefinition)
387402
{
388403
std::string name;

include/SchemaGenerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class Generator
209209
void visitDefinition(const peg::ast_node& definition);
210210

211211
void visitSchemaDefinition(const peg::ast_node& schemaDefinition);
212+
void visitSchemaExtension(const peg::ast_node& schemaExtension);
212213
void visitScalarTypeDefinition(const peg::ast_node& scalarTypeDefinition);
213214
void visitEnumTypeDefinition(const peg::ast_node& enumTypeDefinition);
214215
void visitEnumTypeExtension(const peg::ast_node& enumTypeExtension);

0 commit comments

Comments
 (0)