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

added support for basic variables queries #38

Merged
merged 3 commits into from
Jan 14, 2021

Conversation

ggranberry
Copy link
Contributor

Decided to keep it somewhat minimal here with things like multiple data paths. LMK if anyone knows a better way to handle variable interpolation than my getVariables function. ScopedVariables aren't provided to the metricFindValues function so I had to get them from the templateSrv

@babaMar
Copy link

babaMar commented Dec 14, 2020

After installing the plugin with:

RUN git clone https://github.com/ggranberry/graphql-datasource.git \
  && cd graphql-datasource \
  && git checkout variable-queries \
  && yarn install --no-progress \
  && yarn build \
  && cd ..

RUN mkdir $GF_PATHS_PLUGINS/graphql-datasource \
  && cp -r graphql-datasource/dist $GF_PATHS_PLUGINS/graphql-datasource

and adding the datasource, I get

GraphQL Data Source plugin failed
Error: [$injector:unpr] Unknown provider: eProvider <- e http://errors.angularjs.org/1.6.9/$injector/unpr?p0=eProvider%20%3C-%20e

@ggranberry
Copy link
Contributor Author

Did you restart grafana? I just followed along with the instructions provided here to get things running locally.

Essentially

  • clone the repo and get it to your plugins dir (looks like you have that)
  • I ran yarn dev to get it built
  • restart the grafana server

@retzkek
Copy link
Contributor

retzkek commented Dec 14, 2020

@babaMar that is a known issue with release builds, see #17. In any case you shouldn't have to re-build the plugin, dist is already built.

@ggranberry sorry I haven't had a chance to review this yet, hopefully this week.

@carvid
Copy link
Contributor

carvid commented Dec 17, 2020

@ggranberry Great job!. I started to add query variable support to this plugin but I couldn't find enough time to wrap up my changes. I have a couple of suggestions:

  • Grafana supports key/value pairs for query variables options, it would be great if you can define a data path for each.
  • The field for the query could be resizable since that makes easier to edit long queries (I think other datasources use that for query variables)

@ggranberry
Copy link
Contributor Author

@carvid getting back to this now that the Holidays are over. Can you give me more details on the key/value support? I see the support for multiple data paths in ordinary queries, and I can definitely replicate that.

@ggranberry
Copy link
Contributor Author

@retzkek I got caught up in the Holidays. Did you ever get a chance to take a look?

@carvid
Copy link
Contributor

carvid commented Jan 6, 2021

@carvid getting back to this now that the Holidays are over. Can you give me more details on the key/value support? I see the support for multiple data paths in ordinary queries, and I can definitely replicate that.

@ggranberry sorry for the late response. Basically, you can set a value property along with text property here https://github.com/fifemon/graphql-datasource/pull/38/files#diff-744ba81e1aaee1ed9a56abf8a987f391f665e20d9ed2298b757b2edf6dc8752fR319. Grafana will use value and text when populating the variable selector options.

@ggranberry
Copy link
Contributor Author

@carvid from what I'm seeing in the source MetricFindValue type doesn't accept value as a property. The type is

export interface MetricFindValue {
    text: string;
    expandable?: boolean;
}

@retzkek
Copy link
Contributor

retzkek commented Jan 14, 2021

This looks really good @ggranberry, thank you! Sorry for the delay. I've pushed a change to use the @grafana/ui QueryField component instead of a textarea. It has some nice formatting, dynamic resizing, and will allow us to eventually add syntax highlighting along with the main query editor.

@retzkek retzkek merged commit 63c6c19 into fifemon:master Jan 14, 2021
@tijimathew-iot
Copy link

tijimathew-iot commented Mar 9, 2021

Is this feature available now? I could not find the documentation or examples on how to implement the Query Variables to return text and value so that I can make the grafana dashboards dynamic. A screenshot of an example of this functionality would be great.

EDIT: I may have misunderstood this feature. I was looking for this feature available in PostgresSQL datasource but for GraphQL. https://grafana.com/docs/grafana/latest/datasources/postgres/#query-variable

@retzkek
Copy link
Contributor

retzkek commented Mar 9, 2021

@tijimathew-iot yes this was released in v1.2.0. You use it like any other query variable, e.g. here's the example from the Deutsche Bahn demo:

image

@tijimathew
Copy link

Thank you for responding. Is query returning an array or an dictionary to get list of values?

@retzkek
Copy link
Contributor

retzkek commented Mar 9, 2021

Thank you for responding. Is query returning an array or an dictionary to get list of values?

search.stations is an array of objects.
image

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

Successfully merging this pull request may close these issues.

6 participants