js-graphql-intellij-plugin
js-graphql-intellij-plugin copied to clipboard
[Feature request] Support injection/highlighting in gatsby's "graphql(`...`)"
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
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.
- Gatsby -
graphql(
- Apollo -
gql(
- My project -
dispatch("graphql/query",
- 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.
Fixed in previous releases.
@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 oh, my bad! I closed this prematurely. It will be fixed in 4.0.0.