Skip to content
This repository has been 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
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

keithpitt
Copy link
Member

Does what is says on the Tin!

image

GraphiQL (the editor that this is loosely based on) uses a pretty basic way of doing "prettification"

print(parse(query))

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!

@keithpitt keithpitt requested a review from a team January 17, 2019 02:21
@ticky
Copy link
Contributor

ticky commented Jan 17, 2019

Wow, I was going to ask “how big is Prettier?” and yikes!

image

Good call lazy-loading.

prettifyQuery(this.state.query, (query) => {
this.setState({ query: query });
});
}
Copy link
Contributor

@ticky ticky Jan 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we’d want to do the lazy-load-on-hover trick here? I did it in ImageUploadField:

// Make sure we're loading the image processing code now the user is dragging something around
this.getLoadImage();

getLoadImage = () => {
// If we don't have our import promise stored, create it
if (!this._loadImage) {
this._loadImage = import('blueimp-load-image');
}
// Finally, return the promise
return this._loadImage;
}

withLoadImage = (callback: Function) => {
// Call back with the default loadImage
// function, once the import promise resolves
this.getLoadImage().then((module) => callback(module.default));
}

@plasticine
Copy link
Contributor

brb implementing prettier in dev... 😉😜

@ticky
Copy link
Contributor

ticky commented Jan 31, 2019

@keithpitt are you still planning to land this?

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

Successfully merging this pull request may close these issues.

None yet

3 participants