[lsp-server] 🐞 suggestions after fragment spread
- Dominant language
- TypeScript
- Stars
- 16.9k
- Forks
- 1.9k
- Avg merge
- 22h 45m
- Merged PRs (30d)
- 70
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Current Behavior
`getAutocompleteSuggestions` from `graphql-language-service` wrongly reports suggestions after a fragment spread, while it works before the fragment spread, or using inline fragments.
### Expected Behavior
It properly reports suggestions after fragment spread.
### Steps To Reproduce
The following example shows that **suggestions** after a fragment spread are wrongly reported, while in case of an inline fragment they are ok.
```javascript
const {
getAutocompleteSuggestions,
Position,
} = require("graphql-language-service");
const { buildSchema } = require("graphql");
const schema = buildSchema(`type Query {
me: User
}
type User {
name: String!
}`);
const result1 = getAutocompleteSuggestions(
schema,
`# completion FAILS after fragment
query User1 {
me {
...UserFragment
}
}
fragment UserFragment on User {
__typename
}
`,
// before the fragment the suggestion matches
// new Position(3, 2)
// after the fragment the suggestion differs
new Position(5, 2)
);
const result2 = getAutocompleteSuggestions(
schema,
`# completion WORKS after fragment
query User2 {
me {
... on User {
__typename
}
}
}
`,
// before the fragment the suggestion matches
// new Position(3, 2)
// after the fragment the suggestion differs
new Position(7, 2)
);
console.log("1 ==>", result1);
console.log("2 ==>", result2);
```
Result:
- suggestions after fragment spread: FAILS
- suggestions after inline fragment: WORKS
```text
1 ==> []
2 ==> [
{
sortText: '0name',
label: 'name',
detail: 'String!',
documentation: undefined,
deprecated: false,
isDeprecated: false,
deprecationReason: undefined,
kind: 5,
type: GraphQLNonNull { ofType: [GraphQLScalarType] }
},
{
sortText: '1__typename',
label: '__typename',
detail: 'String!',
documentation: 'The name of the current Object type at runtime.',
deprecated: false,
isDeprecated: false,
deprecationReason: undefined,
kind: 5,
type: GraphQLNonNull { ofType: [GraphQLScalarType] }
}
]
```
### Environment
* graphql-language-service
- version": 5.2.0
### Anything else?
Same example can be copied into **GraphiQL** to see that it happens there too. Try to get suggestion in the empty line after the fragment spread:
https://graphiql-test.netlify.app/?query=query%20Person1%20%7B%0A%20%20person%20%7B%0A%20%20%20%20%0A%20%20%20%20...PersonFragment%0A%20%20%20%20%0A%20%20%7D%0A%7D%0Afragment%20PersonFragment%20on%20Person%20%7B%0A%20%20__typename%0A%7D%0A
While using the inline fragment works:
https://graphiql-test.netlify.app/?query=query%20Person2%20%7B%0A%20%20person%20%7B%0A%20%20%20%20%0A%20%20%20%20...on%20Person%20%7B%0A%20%20%20%20%20%20__typename%0A%20%20%20%20%7D%0A%20%20%20%20%0A%20%20%7D%0A%7D%0A
Contributor guide
Assessment
This issue has not been assessed yet.