Skip to content

Feature request: prettyPrint #1799

New issue

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

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

Already on GitHub? # to your account

Open
mjmahone opened this issue Mar 22, 2019 · 3 comments
Open

Feature request: prettyPrint #1799

mjmahone opened this issue Mar 22, 2019 · 3 comments

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. 😄 👍

@lesleydreyer
Copy link

In case it's been forgotten since it's a couple years later, this feature would be super helpful. Thanks for all you do!

@yaacovCR
Copy link
Contributor

yaacovCR commented Feb 6, 2025

This might depend on #2241 ?

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

No branches or pull requests

5 participants