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

Plugin: lifecycle hook to enable prettifying queries on load #828

Open
rybon opened this issue May 15, 2019 · 10 comments
Open

Plugin: lifecycle hook to enable prettifying queries on load #828

rybon opened this issue May 15, 2019 · 10 comments
Labels
graphiql potential plugin A potential plugin idea for later versions of GraphiQL

Comments

@rybon
Copy link

rybon commented May 15, 2019

Would it possible to auto prettify (opt-in, off by default) GraphGL calls when opening them in a GraphiQL window? I know there's a button in the UI to do this, but I would prefer to have this done as soon as a GraphQL URL is opened, so the extra button click is not needed. Perhaps this can be configured by setting an options object on the graphiql field? So instead of graphiql: true one could set graphiql: { autoPrettify: true } when for example setting up a express-graphql server.

@benjie benjie added the potential plugin A potential plugin idea for later versions of GraphiQL label May 17, 2019
rybon added a commit to rybon/graphiql that referenced this issue May 17, 2019
@rybon rybon mentioned this issue May 17, 2019
@acao
Copy link
Member

acao commented May 17, 2019

@benjie how would this be a potential plugin? seems too simple for a potential plugin

@benjie
Copy link
Member

benjie commented May 17, 2019

Plugins should be able to augment GraphiQL in many ways; one such way is to hook lifecycle events. This same hook could be used in multiple ways, for example to tell the query to run every second via setInterval, or to bind the editor to something else in the application (e.g. a visual block editor, or GraphiQL Explorer, or something else). Similarly they should be able to augment the options object for GraphiQL to add their own options so users of the plugin can configure it via the standard GraphiQL configuration interface.

This is part of my vision for plugins, anyway. I need to set aside some time to write up how I think it can work (and what I think it should be able to do) some time in the next few weeks.

@benjie
Copy link
Member

benjie commented May 17, 2019

One of the great things about plugins is that they enables features like this that are only needed by a small subset of the GraphiQL users to be maintained outside of core, and yet still have deep integration. This keeps core lean, whilst reducing the need to fork the project, and makes it more powerful for its users.

@rybon
Copy link
Author

rybon commented May 17, 2019

I like the idea of plugins, but this particular feature seems too trivial for a plugin and is already present in the code base (under the Prettify button).

@rybon
Copy link
Author

rybon commented May 17, 2019

Here's the express-graphql side of this feature: graphql/express-graphql#507

@benjie
Copy link
Member

benjie commented May 17, 2019

Sure, the code may be simple, but the more options we have out of the box the harder it is for new users to understand, and the more of a maintenance burden we have on keeping the documentation and code up to date, the more places for bugs to hide, and the greater the number of combinations of options that we need to test (e.g. how well do query and autoPrettify work together?).

By handling features like this via a plugin, you can get something that you can use immediately (without having to maintain your own fork) and share with others, and GraphiQL itself can remain a very lean core that only deals with the concerns of the majority of its users.

@rybon
Copy link
Author

rybon commented May 17, 2019

I understand your concerns regarding feature creep and keeping the API surface area and associated permutations limited, but how would one build a plugin for this feature? The method that is invoked is located inside the GraphiQL component. How would a plugin invoke it?

Do we really have to draw a line in the sand for this particular feature? I would understand it a bit better if this was a complicated implementation, but given that the PR only contains 5 LOC (excluding whitespace) and is really straightforward, why start this discussion now?

@acao
Copy link
Member

acao commented May 17, 2019

ok, i'm beginning to see what you guys mean for a plugin system for 1.0 for sure

for the purposes of 0.x, which will be the active version for the next 8 months at least, possibly this will be enough? i imagine 1.0 will probably need a ground-up rebuild

@AGS-
Copy link
Member

AGS- commented May 17, 2019

I agree with @benjie that this should be added as a plugin. Even though I am a huge fan of prettify, I don't think prettify is something that should be on by default since it strips important stuff like comments, etc.

@rybon
Copy link
Author

rybon commented May 17, 2019

@AGS- please review the PR, it won't be on by default. It is opt-in.

@benjie benjie changed the title Auto prettify? Plugin: lifecycle hook to enable prettifying queries on load Dec 10, 2019
@acao acao added this to the GraphiQL-1.0.0-beta milestone Mar 13, 2020
@acao acao added the graphiql label Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
graphiql potential plugin A potential plugin idea for later versions of GraphiQL
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

4 participants