feat: add quick fixes for GraphQL diagnostics#413
Open
JoviDeCroock wants to merge 1 commit into
Open
Conversation
Adds a getCodeFixesAtPosition proxy that offers quick fixes for GraphQLSP's own diagnostics: - 'Did you mean' suggestions in validation messages (52001) become one rename fix per suggested replacement - deprecated fields (52004) whose deprecation reason names a replacement (backtick-quoted word or single identifier after 'use'/'replaced by') get a fix swapping in the replacement - unused fields (52005) get a fix removing them from the document, including their line and indentation, unless the removal would leave the parent selection set empty Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 3ce7328 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What/Why
Editors can request code fixes for the diagnostics GraphQLSP reports, but until now the plugin passed those requests straight through to TypeScript, which has nothing to offer inside a GraphQL document. This adds a
getCodeFixesAtPositionproxy that turns three of the plugin's own diagnostics into one-click quick fixes:Did you mean "a", "b", or "c"?produce one fix per suggestion, replacing just the misspelled token. Suggestions that aren't a plain rename ("Did you mean to use an inline fragment on ...") are skipped.Implementation notes
packages/graphqlsp/src/codeFixes.ts; the proxy inindex.tsfollows the existingguard()pattern and always merges with/falls back toinfo.languageService.getCodeFixesAtPosition(...).getGraphQLDiagnostics, so they reuse the same LRU-cached diagnostics the editor's request is based on and stay consistent with the reported spans.test/e2e/fixture-project-code-fixeswith a schema containing deprecated fields with and without parseable replacements; the existing tada fixture couldn't be extended because its schema is pinned by completion snapshots.Test plan
test/e2e/code-fixes.test.ts(new): asserts the 52001/52004 diagnostics and the exact fix descriptions and text changes for a single suggestion, multiple suggestions (one fix each), "Use `name` instead", "This field is replaced by `power`", and asserts no fix for a reason without replacement.test/e2e/unused-fieds.test.ts(extended): asserts exact whole-line deletions for a top-level and a nested unused field, and that no fix is offered when removing the listed fields would empty the selection set.pnpm --filter @0no-co/graphqlsp run buildpasses; fullpnpm run test:e2epasses: 12 files, 59 tests, 0 failures.🤖 Generated with Claude Code