Skip to content

Conversation

@felipe-gdr
Copy link
Member

@felipe-gdr felipe-gdr commented Jul 24, 2022

Create a PrettyAstPrinter class to enable printing schemas for linting purposes.
This printer will maintain comments and expose options for controlling the formatting of the printed schema.

.indentWith(1)
.build()

def parser = new NodeToRuleCapturingParser()
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be good that the pretty printer would be self contained and not requre the user to parse anything themself.

Copy link
Member Author

Choose a reason for hiding this comment

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

It actually is. I created this static print method that callers can use just passing the schemaDef and options:

    public static String print(String schemaDefinition, PrettyPrinterOptions options) {
        NodeToRuleCapturingParser parser = new NodeToRuleCapturingParser();
        Document document = parser.parseDocument(schemaDefinition);

        return new PrettyPrinter(parser.getParserContext(), options).print(document);
    }

I had created the tests before creating the method, and never got around to change the call in the tests :-)

Copy link
Member

Choose a reason for hiding this comment

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

can reflect this in the test then please

Copy link
Member

@bbakerman bbakerman left a comment

Choose a reason for hiding this comment

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

Consider the naming of pretty printer as mentioned inside

return implementz;
}

private <T extends Node<?>> T captureRuleContext(T node, ParserRuleContext ctx) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a comment somewhere that says if the map is null it means its not used. For future devs.

* @see AstPrinter
*/
@PublicApi
public class PrettyPrinter extends AstPrinter {
Copy link
Member

Choose a reason for hiding this comment

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

What about PrettyAstPrinter as a name

We have today an AstPrinter and a SchemaPrinter - so this printer is a PrettyAstPrinter or AstPrettyPrinter

Copy link
Member Author

Choose a reason for hiding this comment

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

100%!
Just pushed a commit with the change.

@bbakerman bbakerman added this to the 20.0 milestone Aug 11, 2022
* @param nodeClass the class of the {@link Node}
* @param nodePrinter the custom {@link NodePrinter}
*/
protected void replacePrinter(Class<? extends Node> nodeClass, NodePrinter<? extends Node> nodePrinter) {
Copy link
Member

Choose a reason for hiding this comment

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

can mark this either either as Internal or make it package protected instead of protected

* @param <T> the type of node
*/
private interface NodePrinter<T extends Node> {
protected interface NodePrinter<T extends Node> {
Copy link
Member

Choose a reason for hiding this comment

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

can mark this either either as Internal or make it package protected instead of protected

@andimarek andimarek merged commit aeae3dc into graphql-java:master Aug 16, 2022
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.

3 participants