Js-graphql-intellij-plugin: Support for dummy gql tag for testing?

Created on 26 Jun 2017  路  2Comments  路  Source: jimkyndemeyer/js-graphql-intellij-plugin

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. ;-)

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:

// 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.

All 2 comments

... 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.

Was this page helpful?
0 / 5 - 0 ratings