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

Feature request - Trigger the update programmatically (e.g: through CLI)

Open Vadorequest opened this issue 3 years ago • 6 comments

Because I'm running an advanced workflow with several GraphQL endpoints I'd like the ability to invoke the plugin programmatically somehow.

The goal would be to trigger a schema update when another NPM script is being executed.

Is that already possible? Out of the scope? Planned? Considered if a PR is made?

Thank you

Vadorequest avatar Apr 05 '21 14:04 Vadorequest

@Vadorequest hi! To integrate with a plugin you should write your own plugin and publish it to the marketplace or install it from the built zip file manually. Then you will be able to depend on any plugin including this one and call its API. But I'm not sure I understand why do you need to trigger schema update manually, it should be updated whenever any schema-related file is modified.

vepanimas avatar Apr 05 '21 15:04 vepanimas

But I'm not sure I understand why do you need to trigger schema update manually, it should be updated whenever any schema-related file is modified.

I use https://github.com/Plazide/fauna-gql-upload which uploads a GraphQL schema to FaunaDB when running yarn fauna:sync from CLI, and I want to automatically update the GraphQL schema once it's done to make sure to fetch the latest up-to-date version.

Currently, it doesn't refresh it automatically, I guess that's because it's executed from the CLI (outside WebStorm's context).

I won't likely have the time to work on a plugin myself, I was hoping it might be a core feature, although I understand if it's out of the scope of this project. Thanks for the pointers about own plugin, I for sure wouldn't have thought of that!

Vadorequest avatar Apr 05 '21 18:04 Vadorequest

@Vadorequest sorry for the late answer. If the changes were made not from the Webstorm itself, then they are still tracked and this should lead to a schema update, I checked it right now and it works.

Unfortunately, I still don't understand what is required from the plugin side. When you run yarn fauna:sync, does it generate/update a local .graphql file with type definitions? Is that file used by the plugin? Do you have a .graphqlconfig, is it specified there?

vepanimas avatar Jul 20 '21 21:07 vepanimas

Here is the script (it's OSS): https://github.com/Vadorequest/rwa-faunadb-reaflow-nextjs-magic/blob/main/package.json#L7

It basically calls this lib: https://github.com/Plazide/fauna-gql-upload

It's configured through this file: https://github.com/Vadorequest/rwa-faunadb-reaflow-nextjs-magic/blob/main/.fauna.json

Which uses this file as GQL input schema: https://github.com/Vadorequest/rwa-faunadb-reaflow-nextjs-magic/blob/main/fauna/gql/source-schema.gql

And generates this file as output: https://github.com/Vadorequest/rwa-faunadb-reaflow-nextjs-magic/blob/main/src/types/graphql/graphql.ts


This workflow works fine. The issue I have is that I'd also like to refresh the schema.graphql automatically, because that's the one used by WebStorm for auto-completion and debugging. https://github.com/Vadorequest/rwa-faunadb-reaflow-nextjs-magic/blob/main/schema.graphql

To update it, I need to run the plugin through this file on WebStorm: https://github.com/Vadorequest/rwa-faunadb-reaflow-nextjs-magic/blob/main/.graphqlconfig


So, to sum it up, I need to perform 2 manual actions:

  • Run yarn fauna:sync
  • Click on "Run" in .graphqlconfig through WebStorm

What I hoped for is a way to trigger the "Run" automatically when running the yarn fauna:sync script.

Vadorequest avatar Jul 21 '21 07:07 Vadorequest

@Vadorequest ok, thank you for the clear explanation, now I got it. I don't have an idea how to fix it yet and I can't promise that it will be fixed on the plugin side, but I'll try to come up with something.

vepanimas avatar Jul 28 '21 14:07 vepanimas

@vepanimas just want to add that we are in a similar situation. Our schema is stored on the server and we run some scripts on the client-side to generate helpers from the online schema.
Would be great if we can update the schema file with running those scripts. Surprisingly, I couldn't even find a recently maintained npm package to do this.

Edit: Did find a package to handle this. This works well enough for me: Schema AST with graphq-code-generator.

TuringJest avatar Feb 18 '22 13:02 TuringJest