Skip to content

Instantly share code, notes, and snippets.

@joshangell
Last active December 21, 2022 10:13
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshangell/6b590ca1953599303e207f89f0181824 to your computer and use it in GitHub Desktop.
Save joshangell/6b590ca1953599303e207f89f0181824 to your computer and use it in GitHub Desktop.
Quick and dirty explanation of how to get autocomplete, syntax highlighting etc when using Gridsome in PhpStorm.

PhpStorm

  1. Make sure your gridsome dev server is running: cd frontend and then yarn dev or npm run dev
  2. Install JS GraphQL plugin: https://jimkyndemeyer.github.io/js-graphql-intellij-plugin/
  3. Select everything inside <page-query>, click the light bulb icon, choose "Inject language or reference" and select GraphQL, like this:

NOTE: you only have to do this once and then all your .vue files will support GraphQL queries inside <page-query> tags.

  1. Create a file in the root of your project named .graphqlconfig and paste in something like the following:
{
  "name": "My App",
  "schemaPath": "my_endpoint_schema.graphql",
  "extensions": {
    "endpoints": {
      "My App Endpoint": {
        "url": "http://localhost:8080/___graphql",
        "headers": {
          // If you need auth, add it here
          "Authorization": "Bearer TOKEN"
        },
        "introspect": true
      }
    }
  }
}
  1. Now close and reload your project - you should see a bubble in the bottom right of the IDE (see below) asking you if you want to "Get GraphQL Schema from Endpoint now?" (you can also see this in the PhpStorm console) - click the link that says "Introspect 'http://localhost:8080/_graphql'" and boom, it should work!

  1. Once you are up and running you can use GraphQL right inside PhpStorm, just click GraphQL button in the footer:

  1. And now you can use autocomplete!

  1. To update the local schema file that PhpStorm is reading from (for example if you add a field to your API or whatever) then you can use the Update button in the GraphQL tab:

@michael-picard
Copy link

thanks! I'm just starting out with gridsome this will help a lot.

@tanc
Copy link

tanc commented Dec 3, 2019

Thank you for posting these instructions, very helpful 👍

@joshangell
Copy link
Author

Hey @tanc and @michael-picard glad you’re both finding it helpful! You can check out my good friend Andrew’s more detailed write up of this over on his blog: https://nystudio107.com/blog/graphql-schema-auto-completion-with-phpstorm

@Brotzka
Copy link

Brotzka commented Mar 26, 2020

Great, thanks a lot!

@dernetzjaeger
Copy link

Wooohooo! Exactly this is what I was looking for.
You may also mention that it also works for other IntelliJ Platform IDEs like Webstorm.

Thanks a lot! 👍

Copy link

ghost commented Dec 6, 2020

Thank you. Very helpful!

@seriiserii825
Copy link

For me don't work.
I use gridsome, and graphql link is http://localhost:8080/___explore https://i.imgur.com/Es6rSEZ.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment