Some emerging Vue frameworks, remarkably Gridsome, use GraphQL custom blocks for data pre-fetching. Nonethewise, Vetur currently doesn't support GraphQL custom block highlighting.
A possible obstacle is that currently VS Code, by default, doesn't include a graphql language server (for file extension gql).
We do have custom block support, so this is not hard to do. I just need to register graphql as one of the embeddable languages.
@octref
Hi👋
I'm always helped by Vetur :)
I'm looking forward to this work!!
@octref
Many frameworks use custom block to implement a wide variety of functions. I think the lang attribute should be supported.
<config lang="json">
{
"foo": "baz"
}
</config>
<i18n lang="yaml">
...
</i18n>
Can someone post an example and link to docs, how does a graphql custom block look like?
@octref Here, <page-query> and <static-query> are custom GraphQL blocks: https://gridsome.org/docs/data-query-data
@leopiccionia I'm not familiar with gridsome — are these builtin custom blocks, or do you declare <my-query> somewhere in the code and can start using them?
@octref The Vue blocks are builtin. AFAIK the queries run against a local (GraphQL) server, on server-side (similarly to Nuxt's asyncData).
@leopiccionia I'm not familiar with gridsome — are these builtin custom blocks, or do you declare
<my-query>somewhere in the code and can start using them?
@octref There are two types:
<page-query> for pages and templates
<static-query> for layout and components
It's just regular GraphQL between the tags. And yes, you declare those in your .vue file and can use them directly in your templating.
Here you go:

Steps:
Have this setting:
"vetur.grammar.customBlocks": {
"docs": "md",
"i18n": "json",
"page-query": "graphql"
},
Run command Vetur: Generate Grammar
The solution above worked for me...except for <static-query>. So be sure to add it after page-query, like so:
"vetur.grammar.customBlocks": {
"docs": "md",
"i18n": "json",
"page-query": "graphql",
"static-query": "graphql"
}
For those wondering why it doesn't highlight it even after applying @octref 'solution, try restarting VSCode. It didn't work for me when I changed the setting, but after opening VSCode the next day it worked.
Per reloading, I added some docs to https://vuejs.github.io/vetur/highlighting.html
How do you run command this command in VSCODE?
Vetur: Generate Grammar
@dosstx You can run it via the Command Palette (Ctrl+Shift+P).
Isn't it better to make Vetur: Generate Grammar command automatic? Are their limitations in VsCode API to detect config change 🤔
Yes, that is not allowed: https://github.com/microsoft/vscode/issues/68647
Thanks to the post I have syntax highlighting working on the queries, but how do we get proper indentation?
Thanks to the post I have syntax highlighting working on the queries, but how do we get proper indentation?
Any update on this?
Most helpful comment
Here you go:
Steps:
Have this setting:
Run command
Vetur: Generate Grammar