graphql-mode
graphql-mode copied to clipboard
Find a good way to submit variables with a GraphQL query
GraphQL queries can contain variables that have to be sent separately. It would be useful to have a way to submit the variable values.
Look at https://github.com/graphql/graphiql for some examples.
I believe the branch "next" is for this feature.
I've been thinking about this a bit recently, and have come across the following solution:
query Foo {
bar {
fizz
baz {
quux
}
}
}
#$var1 : ?bar.fizz
#$var2 : 4
mutation Blorp($var1 : String!, $var2 : Int) {
...
}
Here the ?bar.fizz refers to the result of the previous query. In general, any ? binder would refer to the query directly above it.
This has a few nice benefits:
- The files remain valid .graphql files.
- You can do variable capturing from previous queries, which is a very common workflow.
I'll look into getting a POC working in the next few days, though a few features need to be added 1st (multiple queries mainly).
Those are nice but it seems more a language on top of GraphQL. Nothing wrong with that, but maybe it should be built on top of grapqhl-mode rather than in it I feel.
I think having a separate buffer for managing bars like GraphIQL is probably the way to go. I see making this mode more "IDE"-like better than a language-like.