Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extend schema (AST print) to SchemaPrinter #3471

Merged
merged 5 commits into from May 21, 2024

Conversation

dondonz
Copy link
Member

@dondonz dondonz commented Feb 24, 2024

This PR enables schema extension printing, reported in #3428.

This PR adds AST printing (which is the only way to get at the extend extension definition). We had the methods in place inside the AST printer, this PR adds this to the SchemaPrinter.

@dondonz dondonz changed the title WIP Add extend schema to SchemaPrinter Add extend schema to SchemaPrinter May 1, 2024
@dondonz dondonz marked this pull request as ready for review May 1, 2024 21:15
private boolean shouldPrintAsAst(SchemaDefinition definition) {
return options.isUseAstDefinitions() && definition != null;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to type definition version above

}
out.print('\n');
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to type definition version above. This prints everything including directives and description.

if (subscriptionType != null) {
out.format(" subscription: %s\n", subscriptionType.getName());
if (shouldPrintAsAst(schema.getDefinition())) {
printAsAst(out, schema.getDefinition(), schema.getExtensionDefinitions());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main change on this line: if AST flag is on, use the new AST print method for SchemaDefinition

out.format(" subscription: %s\n", subscriptionType.getName());
if (shouldPrintAsAst(schema.getDefinition())) {
printAsAst(out, schema.getDefinition(), schema.getExtensionDefinitions());
} else {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What follows is the original code, this will run if AST switch is off


extend schema @schemaDirective {
query: MyQuery
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: although there is an implicit schema block if it is not specified, if you want to extend schema you MUST also have an explicit schema block defined in the schema.

'''
}

def "will not print extend schema block when AST printing not enabled"() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If AST switch is off, all extend definitions are combined.

@dondonz dondonz changed the title Add extend schema to SchemaPrinter Add extend schema (AST print) to SchemaPrinter May 1, 2024
@bbakerman bbakerman added this pull request to the merge queue May 21, 2024
Merged via the queue into master with commit f93fdac May 21, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants