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

Rich query editor (graphiql) #11

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

Rich query editor (graphiql) #11

retzkek opened this issue Apr 25, 2020 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@retzkek
Copy link
Contributor

retzkek commented Apr 25, 2020

Provide a rich schema-aware query editor. We should be able to leverage the graphiql components.

@retzkek retzkek added this to the v2.0 milestone May 11, 2020
@retzkek retzkek added enhancement New feature or request help wanted Extra attention is needed labels May 11, 2020
@retzkek retzkek mentioned this issue Jun 26, 2020
@retzkek retzkek modified the milestones: v2.0, v1.3.0 Mar 4, 2021
@retrodaredevil
Copy link
Contributor

I was looking into this (again) and was attempting to get this working from my limited React and NPM/Yarn knowledge.

I spent way to long trying to get a newer version of graphql and graphiql to build via yarn dev.

I ended up getting

    "graphiql": "1.0.6",
    "graphql": "15.4.0"

to work as dependencies, which is what Grafana abandon GraphQL Datasource uses. The important part was making sure my yarn.lock had older a graphql-language-service-interface version that doesn't use the new JavaScript optional chaining stuff.

After getting yarn dev to build, I played with replacing the QueryField in QueryEditor.tsx with GraphiQL:

        <GraphiQL
          query={queryText || ''}
          fetcher={fetcher}
          editorTheme={'dracula'}
          onEditQuery={this.onChangeQuery}
        />

The fetcher I copied from here.

After all that, it... does something. I guess the functionality is technically there, since I can see something that resembles the documentation of my GraphQL schema in the editor, but the CSS is seriously messed up or I'm just not using the GraphiQL tag correctly.

I'm gonna keep attempting to figure this out for a little while longer, but if anyone wants to add on to the knowledge of navigating whatever the heck is going on here, leave another comment.

@retrodaredevil
Copy link
Contributor

So all I had to do was throw a stylesheet reference in there, and it looks correct.

@retzkek the default GraphiQL stuff has a result viewer window and a tab to edit query variables. I was thinking that I would remove both of those tabs, as this doesn't support query variables yet, and the result viewer isn't helpful because you can just do it in Grafana, plus the query button inside the editor doesn't replace the variables inside the query.

Here's a picture of my progress:
image

The doc tab is a little glitchy when typing in the query, but other than that it works pretty well. I think to remove some of the stuff I'll have to create my own react component, which will likely just be me copy-pasting stuff until it works.

@retzkek
Copy link
Contributor Author

retzkek commented Mar 29, 2022

@retrodaredevil awesome, thanks for continuing to plug away at this.

the default GraphiQL stuff has a result viewer window and a tab to edit query variables. I was thinking that I would remove both of those tabs

I agree.

@retrodaredevil
Copy link
Contributor

More progress today. I will be attempting to upgrade the GraphiQL version again soon. I ended up using CSS to hide the stuff I didn't want to see.

@retzkek it looks like they added support for react for annotations in Grafana 7.2. I'm not going to update it to use the same default query editor because that will break users' custom text. But when we do want to make that change, it's as simple as adding this.annotations = {} in DataSource's constructor. I will try and have some code sharing between VariableQueryEditor.tsx and QueryEditor.tsx, but I think this is mostly done. Hoping for a PR in the next week as I'm pretty busy these next few days.
image

@retzkek
Copy link
Contributor Author

retzkek commented Mar 31, 2022

You can make the annotations editor change in the same PR, we'll announce it as a breaking change, and I think most people will be fine with it since it's a huge improvement. Take your time on the PR, I probably won't be able to review it for at least a week or two.

@retrodaredevil
Copy link
Contributor

I wasn't going to make that change because it would take away a feature that I use. I like that I'm able to create custom text with data from the query substituted in, but the new way by default only allows you to select a field to be the title, text and tags. I would like to keep that feature.

It also doesn't make sense to have "Group by" and "Alias by" in annotation queries. I might get around to looking at the best way to do this, or I might not. It will likely be something I do eventually. There might be a way to do it without having it be a breaking change.

@retrodaredevil
Copy link
Contributor

retrodaredevil commented Apr 7, 2022

@retzkek I've begun making many changes to getting annotation stuff working. Grafana provides these options for setting many of the properties we were setting ourselves.

image

Since it now requires a field to provide for title, text and tags, I am going to create another setting for users to configure called something like "additional text fields". Users will be able to name these fields whatever they want and provide text for these fields that will be substituted just like the title, text and tags fields were. Doing this will even allow old configurations to be recognized and automatically converted to the new format, so there won't be any breaking changes.

I'm debating making the "additional text fields" available to variable and regular queries, but not sure how useful that would be.

This is the direction I'm going. Let me know if you have any feedback. I'm also waiting on graphiql to be updated so that I can use the newer version, which is basically a requirement before releasing this change because the version right now has a vulnerability.

I'm also making changes to remove some of the legacy options such as "constant" and "endTimePath", so the resulting JSON should be much cleaner for each type of query and won't have any unnecessary fields.

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

No branches or pull requests

2 participants