autocompletion `insertText` for object/list/union/interface fields, fill required leafs with a selection set
- Dominant language
- TypeScript
- Stars
- 16.9k
- Forks
- 1.9k
- Avg merge
- 22h 45m
- Merged PRs (30d)
- 70
Description
i got this properly for the right field type completions, added `command` to the completion item to trigger completion (i couldn't get triggerCharacters working for this alone), and either inserted the cursor in between empty braces on new lines, or generate a selection set if there are required fields
```graphql
{
n| <- cursor
}
```
chooses `nullableFieldsObject`, automatically opens selection set and
```graphql
{
nullableFieldsObject {
| (with completion open)
}
}
```
this is how it works by default.
if you have `{fillLeafsOnComplete: true}` in the new `getAutocompleteSuggestions` param, or if configured in `monaco-graphql` or `graphql-language-service-serve`, we append this `insertText` to the appropriate result items
`myObject` is a field that points to a type with non-nullable fields `id` and `items` list with a non-nullable value `value`:
```graphql
{
myObject {
id
items {
value
}
}| #< cursor appears here because it's easiest, should we make it appear somewhere else?
}
```
it's not easy to decide where the cursor should go in this case. any ideas? maybe it could instead do this:
```graphql
{
myObject {
id
items {
value
| #< trigger completion after the deepest required field that is part of a parent object with other available fields.
}
}
}
```
though required arguments are not an easy problem to solve, I did get that working.
i introduced an `options` param to `getAutocompleteSuggestions` but would really just like to finally make a breaking change to this API
TODO:
- [x] move `fillLeafs` from `graphiql/src/utilities` to `graphql-language-service-utils`
- [x] automatically filling in leafs when `fillLeafsOnComplete` is enabled
- [x] append empty selection set with cursor inside & completion when `fillLeafsOnComplete` is enabled
- [ ] have both `fillRequiredLeafs` and `fillAllLeafs` options instead
- [ ] make them available as code actions in `monaco-graphql` and `graphql-language-service-server`
- [ ] make them commands in `monaco-graphql` and `vsode-graphql` with keyboard shortcuts.
- [ ] cross reference historical issues/feature requests related to this
Contributor guide
Assessment
This issue has not been assessed yet.