Skip to content

fix(graphql-language-service): suggest fields after a fragment spread - #4760

Open
unrevised6419 wants to merge 1 commit into
graphql:mainfrom
unrevised6419:fix/autocomplete-fields-after-fragment-spread
Open

unrevised6419 wants to merge 1 commit into
graphql:mainfrom
unrevised6419:fix/autocomplete-fields-after-fragment-spread

Conversation

@unrevised6419

@unrevised6419 unrevised6419 commented Nov 7, 2026 •

Copy link
Copy Markdown

Summary

Field autocomplete returned nothing on an empty position right after a fragment spread:

query {
  me {
    id
    ...UserFragment
    | # <- Ctrl+Space: "No suggestions"
  }
}

After a complete spread name, the online parser stays in the FragmentSpread state at step 2 (waiting for optional directives, or step 3 with experimental fragment arguments). getAutocompleteSuggestions only handled FragmentSpread at step 1 (the fragment name), so this position fell through every branch. typeInfo.parentType is already set there, so this change routes FragmentSpread with step > 1 to the existing field-name suggestions, the same way a Field state after its name already works.

Fixes #3437

Changes

  • getAutocompleteSuggestions.ts: include FRAGMENT_SPREAD && step > 1 in the field-name branch.
  • Add a regression test, with and without experimentalFragmentArguments.
  • codemirror-graphql hint.test.ts: drop the case that asserted no suggestions after query { ...Foo (it encoded this bug).
  • Add a patch changeset for graphql-language-service.

How to verify

  1. Run npx vitest run packages/graphql-language-service/src/interface/__tests__/getAutocompleteSuggestions.test.ts -t "after a fragment spread".
  2. Or run the "VS Code LSP Extension: Run" launch config, put the cursor on an empty line after a ...Fragment spread and trigger completion: the parent type's fields are suggested.

graphql-language-service (304) and codemirror-graphql (69) tests pass. Also checked manually in the VS Code extension:

image

Note: fields are now also suggested on the same line after the spread (...Foo |), where a directive could also follow, which matches how completion already behaves after a field name ({ id |).

🤖 Generated with Claude Code

AI assisted

After a complete fragment spread name the parser stays in the
FragmentSpread state (waiting for optional directives), which no
completion branch handled, so an empty position after `...Foo`
returned no suggestions. Treat it like a field state and suggest the
parent type's fields.

Fixes graphql#3437

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b7948e3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
graphql-language-service Patch
codemirror-graphql Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[lsp-server] 🐞 suggestions after fragment spread

1 participant