graphql / graphql/graphiql

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

Open
#2,467 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
16.9k
Forks
1.9k
Avg merge
22h 45m
Merged PRs (30d)
70

Description

The following works fine and the autocomplete works as expected:

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

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

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.