graphql-mode icon indicating copy to clipboard operation
graphql-mode copied to clipboard

Find a good way to submit variables with a GraphQL query

Open davazp opened this issue 9 years ago • 3 comments

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.

davazp avatar Oct 16 '16 13:10 davazp

I believe the branch "next" is for this feature.

timoweave avatar Oct 02 '17 07:10 timoweave

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:

  1. The files remain valid .graphql files.
  2. 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).

TOTBWF avatar Oct 17 '19 15:10 TOTBWF

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.

davazp avatar Oct 18 '19 06:10 davazp