This repository was archived by the owner on Mar 1, 2019. It is now read-only.
Add a "Prettify" button to the in-app GraphQL Console#767
Open
Add a "Prettify" button to the in-app GraphQL Console#767
Conversation
Contributor
ticky
approved these changes
Jan 17, 2019
| prettifyQuery(this.state.query, (query) => { | ||
| this.setState({ query: query }); | ||
| }); | ||
| } |
Contributor
There was a problem hiding this comment.
I wonder if we’d want to do the lazy-load-on-hover trick here? I did it in ImageUploadField:
frontend/app/components/shared/ImageUploadField.js
Lines 149 to 150 in bb8aaed
frontend/app/components/shared/ImageUploadField.js
Lines 205 to 213 in bb8aaed
frontend/app/components/shared/ImageUploadField.js
Lines 215 to 219 in bb8aaed
Contributor
|
brb implementing prettier in dev... 😉😜 |
Contributor
|
@keithpitt are you still planning to land this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Does what is says on the Tin!
GraphiQL (the editor that this is loosely based on) uses a pretty basic way of doing "prettification"
Essentially it parses the query into an AST, and re-prints the AST with some standard formatting rules. The biggest drawback with this approach is that comments aren't part of the AST, so they're dropped on the floor after hitting the "pretty" button - which is kinda shitty.
I've opted for pulling in the "prettier" package instead and which does do the right thing with comments. I'm doing a magical Webpack import thing since it's only used in this one place and there's no need to import for everything and bloat the main packages - hopefully I did it right!