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

API Proposal: Code Formatting, Prettier #1517

Open
acao opened this issue Apr 29, 2020 · 4 comments
Open

API Proposal: Code Formatting, Prettier #1517

acao opened this issue Apr 29, 2020 · 4 comments

Comments

@acao
Copy link
Member

acao commented Apr 29, 2020

Currently:

We aren't using prettier, instead a lightweight custom solution that has issues, and is not configurable.

Proposed

  • Use prettier for graphql, json, yaml, etc.
  • make it fully configurable by users
  • make it available via command palette, right click context menu, and key commands
  • allow formatting on paste, format range, etc
  • asynchronously imports prettier standalone/graphql parser (500kb minified!)
  • offload computationally expensive work to the webworker process, to increase scalability for large operations or variables.

RFC In Progress

A basic example of formatting graphql with monaco using key shortcuts, context menu and command palette

This PR implements all of the above using monaco and a new language service class: acao#17

It performs the prettier parsing and formatting entirely in the monaco language service webworker thread, and integrates cleanly with monaco's built in formatting provider capabilities. Thus why format on paste, etc is built in! hooray monaco

Todo

  • Document monaco-graphql formatting configuration API
  • allow a formattingConfiguration prop to pass to new monaco-graphql API
  • document how to use new GraphiQL editorConfig prop to enable formatOnPaste
  • expose API to programatically format operation (for an eventual button)

Originally, we were going to make this a plugin, however, the formatting is already so tightly integrated with monaco, and we asynchronously load prettier on the first format run so, it's not as daunting as it had seemed before. 500kb is a LOT to consider. prettier/standalone sounds small, but check it out on bundle phobia

@acao acao added the proposal label Apr 29, 2020
@acao acao changed the title Proposal: Code Formatting, Prettier Core API Proposal: Code Formatting, Prettier Apr 29, 2020
@acao acao changed the title Core API Proposal: Code Formatting, Prettier API Proposal: Code Formatting, Prettier Apr 29, 2020
@acao acao modified the milestones: GraphiQL-1.0.0-beta, GraphiQL-2.0.0-beta May 4, 2020
@bitjson
Copy link

bitjson commented Sep 28, 2020

Hey @acao, thanks for all your work on graphiql!

What's the status on this issue? Are you still working on your feat/use-context-hooks branch? Are you still looking for help testing?

I think built-in Prettier support would really improve the developer experience, and I would agree that increasing the bundle size isn't a big concern.

E.g. it looks like the Hasura console weighs in at ~13 MB right now (gzipped, and ~12 MB is javascript), and that hasn't seemed to matter at all in my use. I'd happily trade bundle size for developer experience any day. 👍

@acao
Copy link
Member Author

acao commented Sep 28, 2020

@bitjson monaco-graphql already fully supports this! the context RFC PR is merged but we decided to explore other directions since context is unsuitable for performance reasons. it uses the monaco-graphql formatter, which uses prettier, and allows custom prettier settings!

@acao
Copy link
Member Author

acao commented Sep 28, 2020

I started work on new new roadmap issue for GraphiQL 2, to summarize the next phase of GraphiQL RFC development:

#1683

this will replace the other pinned milestone issue

@dimaMachina
Copy link
Collaborator

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

Successfully merging a pull request may close this issue.

3 participants