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

Feature request: prettyPrint #1799

Open
mjmahone opened this issue Mar 22, 2019 · 1 comment
Open

Feature request: prettyPrint #1799

mjmahone opened this issue Mar 22, 2019 · 1 comment

Comments

@mjmahone
Copy link
Contributor

Request: Add a Pretty-Printing function to go from AST => well-formatted string

This is a utility I've wanted to exist as part of the core library for a long time. @adek05 began a simple implementation of this in #1557. The Prettier library has even implemented a version of this: https://github.com/prettier/prettier/tree/master/src/language-graphql

Ideal API (I think)

  • Should take in a "max-width" as configuration (default to 80 chars?)
  • Should preserve comments from the original source
  • Should be extensible in the future to support prettier-like configs

Why not re-use print?

  • Ideally, print is as high-performance as possible. I imagine calculating line-width will be a non-trivial performance regression, as would preserving comments.
  • print currently does not preserve comments, and it would potentially break tooling that depends on this comment-stripping feature.
  • This would likely be experimental. We should make sure the output is "ideal" before making the default print functionality be "pretty".

What are potential use cases?

  • Codemod tooling that wants to do a one-time insertion of an AST node into existing GraphQL source files. The current print re-formats and strips comments, and leads to super-long lines if, for instance, your query has more than 4 variable definitions.
  • Test output snapshots would be easier to read, and easier to see how they change over time
  • Prettier and prettier-like tooling could consume this new print function directly
@mjmahone mjmahone modified the milestones: v14.2.0, v15.0.0 Mar 22, 2019
@imolorhe
Copy link

Was just about to create an issue for this. 😄 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants