In testing, it's useful to pass queries as raw unparsed strings to graphql-server, rather than as DocumentNodes, but it would be nice to get highlighting and checking when authoring them. Is there some way to create a dummy gql tag that triggers the plugin, but at runtime does nothing to the string?
If not, consider this another enhancement request.
Whining is the best complement. ;-)
... answering my own question: if you don't need mixed usage in a single file (both real and dummy gql), simply implement a dummy gql tag like so:
function gql(strs, ...exprs) {
// if there are any expressions included in the literal
if (exprs.length !== 0) {
const n = strs.length - 1
let result = ''
for (let i = 0; i < n; i++) {
result += strs[i] + exprs[i]
}
result += strs[n];
return result
}
// if there are no expressions included in the literal
else
return strs[0]
}
Thanks for adding a solution.
You can also trigger language injection by adding a language comment above a variable that declares a GraphQL string:
// language="GraphQL"
This is a generic feature in IntelliJ/WebStorm which also works for other language hosts and injected languages. A typical use case is HTML inside JavaScript strings.
Note that if you add the comment after you've created the GraphQL string, you have to edit the GraphQL for syntax highlighting to take effect.
Most helpful comment
Thanks for adding a solution.
You can also trigger language injection by adding a language comment above a variable that declares a GraphQL string:
This is a generic feature in IntelliJ/WebStorm which also works for other language hosts and injected languages. A typical use case is HTML inside JavaScript strings.
Note that if you add the comment after you've created the GraphQL string, you have to edit the GraphQL for syntax highlighting to take effect.