Js-graphql-intellij-plugin: [Feature request] Support injection/highlighting in gatsby's "graphql(`...`)"

Created on 23 Oct 2019  路  6Comments  路  Source: jimkyndemeyer/js-graphql-intellij-plugin

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

enhancement

Most helpful comment

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.

All 6 comments

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.

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.

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

any updates on that?

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.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Globegitter picture Globegitter  路  5Comments

BerndWessels picture BerndWessels  路  5Comments

ryanquinn3 picture ryanquinn3  路  5Comments

smmoosavi picture smmoosavi  路  3Comments

oknesar picture oknesar  路  5Comments