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

[Feature request] Support injection/highlighting in gatsby's "graphql(`...`)"

Open le0nik opened this issue 4 years ago • 6 comments

Thanks for an incredibly useful plugin!

Gatby has an unusual way of calling graphql in it's Node Apis.

const result = await graphql(`
    query {
      allMarkdownRemark {
        edges {
          node {
            fields {
              slug
            }
          }
        }
      }
    }
  `)

In this case graphql is not a tag, but a function that returns a Promise. It would be nice if this plugin was able to recognize queries inside of it. You can see an official example here https://www.gatsbyjs.org/docs/node-apis/#createPages

le0nik avatar Oct 23 '19 13:10 le0nik

Hi le0nik.

Thanks for using the plugin.

I'll label this as an enhancement.

For now you can manually trigger GraphQL language injection by adding a //language=GraphQL comment on the line above the graphql function, e.g.:

//language=GraphQL
const result = await graphql(`
    query {
      allMarkdownRemark {
        edges {
          node {
            fields {
              slug
            }
          }
        }
      }
    }
  `)

Best regards, Jim.

jimkyndemeyer avatar Oct 23 '19 16:10 jimkyndemeyer

I believe syntax highlight detection is different per framework.

Example.

  1. Gatsby - graphql(
  2. Apollo - gql(
  3. My project - dispatch("graphql/query",
  4. VSCode defaults - const QUERY = /* GraphQL */

In other words, this should be configurable.

koresar avatar Dec 09 '19 00:12 koresar

Please add support for /* GraphQL */, this is very much needed

jimmyn avatar Mar 16 '20 09:03 jimmyn

any updates on that?

stingrigs avatar Sep 29 '20 12:09 stingrigs

There's also this that is supported in VSCode: adding #graphql at the beginning of the graphql query, which is less boiler plate than //language=GraphQL:

const query = `#graphql
    query {
      allMarkdownRemark {
        edges {
          node {
            fields {
              slug
            }
          }
        }
      }
    }
  `

It could also help with the other use cases (gatsby, ...) although it being configurable would obviously be better.

coyotte508 avatar Dec 15 '20 11:12 coyotte508

Another option to have the syntax highlighting done automatically is to set up Language Injection.

If you use the Places Pattern:

+ jsLiteralExpression().withParent(psiElement().withText(string().contains("/* GraphQL */")))

Works great for me, but I haven't tested it for any side effects. Then again, I'm also not using the /* GraphQL */ comment anywhere else.

FelixTellmann avatar Mar 02 '21 06:03 FelixTellmann

Fixed in previous releases.

vepanimas avatar Feb 24 '23 21:02 vepanimas

@vepanimas: I just tested language injection detection using graphql() function, but it does not seem to work with v3.4.0 of the plugin (the #graphql comment does work though). I am using the graphql function from graphql-codegen though, if that matters.

https://github.com/JetBrains/js-graphql-intellij-plugin/issues/294#issuecomment-563014927 has a point also - there are a lot of ways to consume graphql - it would perhaps be beneficial to have this configurable in .graphqlconfig

andoks avatar Mar 02 '23 12:03 andoks

@andoks oh, my bad! I closed this prematurely. It will be fixed in 4.0.0.

vepanimas avatar Apr 10 '23 19:04 vepanimas