graphql / graphiql

GraphiQL & the GraphQL LSP Reference Ecosystem for building browser & IDE tools.
MIT License
16.09k stars 1.72k forks source link

API Proposal: Code Formatting, Prettier #1517

Open acao opened 4 years ago

acao commented 4 years ago

Currently:

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

Proposed

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: https://github.com/acao/graphiql/pull/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

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

bitjson commented 4 years ago

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 commented 4 years ago

@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 commented 4 years ago

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

https://github.com/graphql/graphiql/issues/1683

this will replace the other pinned milestone issue

dimaMachina commented 2 months ago

Available in https://github.com/graphql/graphiql/releases/tag/graphiql%404.0.0-alpha.5