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

Support GraphQL query variables #12

Open
retzkek opened this issue Apr 25, 2020 · 5 comments
Open

Support GraphQL query variables #12

retzkek opened this issue Apr 25, 2020 · 5 comments
Labels
enhancement New feature or request
Milestone

Comments

@retzkek
Copy link
Contributor

retzkek commented Apr 25, 2020

Since GraphQL has first-class variables we should use those rather than directly interpolating in the query string.

@retzkek retzkek added this to the v2.0 milestone May 11, 2020
@retzkek retzkek added the enhancement New feature or request label May 11, 2020
@Totalus
Copy link
Contributor

Totalus commented May 14, 2020

An easy way to implement this is to use two distinct fields in the query configuration, one with the query, another with the variables as a JSON string. The variable string can easily be appended in the POST request to the graphql server. The expressions (e.g. Grafana global variables) could then be replaced in the variable string instead of the query string (or in both if relevant).

@retzkek
Copy link
Contributor Author

retzkek commented May 14, 2020

That's a good idea @Totalus, and is how graphiql does it, making it easy for one to copy-paste queries. We'll need to be careful about quoting, can we do any better than raw substitution and leaving quoting up to the user?

The expressions (e.g. Grafana global variables) could then be replaced in the variable string instead of the query string (or in both if relevant).

This is also tricky - do we make a breaking change and only do interpolation in the variable document, or do we risk doing unintended substitutions in the query body (since both Grafana and GraphQL use $var syntax)?

@Totalus
Copy link
Contributor

Totalus commented May 14, 2020

I didn't mean to "quote" the expressions to replace, sorry for the confusion. As you say it should be raw substitution and quoting of the variables left to the user.

As for the breaking change, if Grafana 7.0 implies some breaking changes in this plugin (not sure about that, you would know more than I do), we could possibly make the change at the same time.

@retzkek
Copy link
Contributor Author

retzkek commented May 14, 2020

I didn't mean to "quote" the expressions to replace, sorry for the confusion.

Sorry, I wasn't referring specifically to anything you said, just thinking out loud.

As for the breaking change, if Grafana 7.0 implies some breaking changes in this plugin (not sure about that, you would know more than I do), we could possibly make the change at the same time.

I've started working on upgrading to Grafana v7 libraries. Some components have moved around (as usual...) but I don't think there's anything that will require a user-facing change.

@Zeeeski
Copy link

Zeeeski commented Mar 28, 2023

Did this ever get implemented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants