js-graphql-intellij-plugin icon indicating copy to clipboard operation
js-graphql-intellij-plugin copied to clipboard

Persist the variables of GraphQL operations

Open andresrinivasan opened this issue 7 years ago • 12 comments

I added variables by toggling the variables window and then adding them. When I close the variables window the variables are lost.

Is there a way to persist this setting? Or perhaps there is an external .json file I need to create to hold the variables?

andresrinivasan avatar Jun 03 '17 22:06 andresrinivasan

This isn't supported at the moment. A PR would be great :)

jimkyndemeyer avatar Jun 07 '17 19:06 jimkyndemeyer

Moreover, when I open variable window and add there a very big variable (several screens), variable window overlaps main editor window. There is a workaround with creadcrumb right-click -> "jump to source" and open '/GraphQL.variables.json' in new editor window. So you can edit variables in normal way. But it will be gone anyway after some actions.

Starkom avatar Aug 24 '18 03:08 Starkom

I'd also like a variable file, I'm importing existing content so I'd need it to store the values, typing them by hand isn't reliable in my case, but a good option for scripting

Vadorequest avatar Mar 31 '19 16:03 Vadorequest

The upcoming 2.0.1 release no longer clears the variables editor when closing it.

There are still some open questions:

  • If persistence is involved, how is cleanup and validation handled?
  • If variable files should be supported, how are they linked to the queries in a way that is intuitive and supported by the editing UI?
  • What if there are multiple queries in the same graphql file?
  • Would it make sense to type the variables using the GraphQL language, but then have JSON conversion actions? The existing GraphQL completion and error highlighter could then be applied to the variables editor.

jimkyndemeyer avatar Apr 14 '19 08:04 jimkyndemeyer

The way I see it for my use case would be as follow:

  • Have a "template" without values (use variable references) in a file
  • Have an "implementation" that somehow references a template and define the values to be used against that template (could handle "a set/array" of variables, to run the template multiple times through the same "implementation" file, nice-to-have)
  • Make the "implementation" file executable by the plugin

This way, it would be very customisable, the template could be generated dynamically or manually, same goes for the implementation. It could be tracked by git, and could be used to manage utility scripts such as importing predefined content.

I would typically use this for migrating data, basically write the templates by hand and the iterate over existing data to generate the "implementation" files and be able to run them again by hand (several at once? nice-to-have) I would also use it to write my own utility suite of scripts to perform redundant actions much faster.

Vadorequest avatar Apr 14 '19 12:04 Vadorequest

I would also be super happy to store my editor variables so I can test quickly my queries after I rest the IDE

denys-meloshyn avatar Apr 21 '20 20:04 denys-meloshyn

As a possible solution, maybe it is possible to store variables as json file and associate them to query?

denys-meloshyn avatar Apr 21 '20 20:04 denys-meloshyn

As a possible solution, maybe it is possible to store variables as json file and associate them to query?

I was about to open up an issue with this suggestion. It would be nice to keep variables in a file for posterity reasoning. Right now we're keeping in variables in separate json file and a contributor has to manually move them to the variable window to test the queries :|

as @Starkom pointed out the variables are already in /GraphQL.variables.json file? I can't find it anywhere and creating one in root directory (next to config) doesn't make a difference.

Granitosaurus avatar Apr 22 '20 05:04 Granitosaurus

Love this extension. Really super powerful, I use it a lot. Thanks for doing this!

Seeing that the readme for v4 mentions variables, I was digging deeper into this and from what I can tell now variables are supported by a project root 'graphql.variables.json' file? When selecting the yellow V from the GraphQL toolbar nothing happens, but reading the source code I understood this is the expected file name (?)

Defining key-value pairs in this file however does not have any effect - does it need to be included or activated somehow?

WebStorm 2023.1, Build #WS-231.8109.174. Runtime version: 17.0.6+10-b829.5 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS ventura 13.1

olof-nord avatar Apr 21 '23 13:04 olof-nord

@olof-nord Oh, looks like we have an issue with 2023.1 😮. It's expected to work like that, and it works in 2022.3, but not in 2023.1. I'll check it.

https://user-images.githubusercontent.com/10243762/233806816-82418f3e-42fa-4812-9e8e-4402353582c5.mp4

vepanimas avatar Apr 22 '23 21:04 vepanimas

Just upgraded to 4.0.1 and the variables editor is working. Thank you!

olof-nord avatar May 15 '23 09:05 olof-nord

Hello, is there any chance variable persistence will be implemented in the future?

It is really frustrating to enter variables again and again from time to time.

yhc44 avatar Apr 27 '24 18:04 yhc44