graphiql icon indicating copy to clipboard operation
graphiql copied to clipboard

[vscode-graphql] use of fragment variable in template string breaks autocomplete

Open CreativeTechGuy opened this issue 3 years ago • 0 comments

The following works fine and the autocomplete works as expected:

const query = /* GraphQL */ `
    query GetItem($name: String!) {
        getItem(name: $name) {
            id
        }
    }
`;

But when it is changed to the following, the autocomplete breaks:

const fragment = /* GraphQL */ `
    fragment PartialItem on Item {
        name
        age
        job
    }
`

const query = /* GraphQL */ `
    ${fragment}
    query GetItem($name: String!) {
        getItem(name: $name) {
            id
            ...PartialItem
        }
    }
`;

What I've figured out so far:

  • If the fragment is in-lined in the query, it works as expected. So it is due to it being a separate variable.
  • Actually using the fragment in the query is not needed to break it. Simply adding ${fragment} is all that is needed to break it.
  • When "broken" the auto complete will always suggest the same options as if the entire template string was empty.

CreativeTechGuy avatar Jun 02 '22 18:06 CreativeTechGuy