Skip to content

feat: support @gql-tada-ignore-unused comment to suppress unused field diagnostics - #433

Open
OMD-123 wants to merge 1 commit into
0no-co:mainfrom
OMD-123:feat/ignore-unused-fields
Open

feat: support @gql-tada-ignore-unused comment to suppress unused field diagnostics#433
OMD-123 wants to merge 1 commit into
0no-co:mainfrom
OMD-123:feat/ignore-unused-fields

Conversation

@OMD-123

@OMD-123 OMD-123 commented Sep 6, 2026

Copy link
Copy Markdown

Summary

This PR introduces support for suppressing "unused field" diagnostics in GraphQL documents using a specific comment directive. This allows developers to explicitly mark a query as "used" even if not all fields are accessed within the same file—a common scenario when passing a full data object to another function or storage mechanism (e.g., localStorage.setItem, caching, or passing to external APIs).

Fixes #269

Changes

  • Added a helper function hasIgnoreUnusedComment in packages/graphqlsp/src/fieldUsage.ts that scans for @gql-tada-ignore-unused or @gql-tada-mark-used in the leading/trailing comments of a graphql() call expression.
  • Modified the diagnostic loop in checkFieldUsageInFile (Phase C) to skip unused field reporting if this comment is present.
  • Added a test fixture test/e2e/fixture-project-unused-fields/fixtures/ignore-test.tsx to verify the behavior.

Example Usage

// @gql-tada-ignore-unused
const MyQuery = graphql(`
  query Me {
    me {
      id
      username
      email
    }
  }
`);

const res = await client.query(MyQuery, {});
// No warnings, even though id, username, email are not individually accessed
saveToCache(res.data.me);

Testing

  • Verified that the plugin continues to report unused fields for documents without the directive.
  • Verified that documents with the directive no longer trigger unused field warnings.

@changeset-bot

changeset-bot Bot commented Sep 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d663c94

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

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.

RFC: Mark certain queries as used even no attributes are accessed

1 participant