Skip to content

feat: Expand tracking unused fields support to more cases #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 23, 2024

Conversation

kitten
Copy link
Member

@kitten kitten commented Feb 23, 2024

Resolves #229
Resolves #224

Summary

Previously, the crawler tracking unused fields wasn't using the type checker to assist with its search of GraphQL data variables. This meant that we were carefully limiting the amount of cases we'd support.

However, as it's hard for us to account for every GraphQL client (that supports TypedDocumentNode) with every possible API (not just hooks, for example, or nested functions inside hooks), we now attempt to find a more general solution.

This PR, when merged, adds a new primary method of discovering where a GraphQL document is used. This new method finds variables in-scope at the point the document is referenced and then matches the type of these variables against the type of the document.
When a match is found, we then know to start tracking field usage for the given variable.

Set of changes

  • Find variables matching a document data types and prefer them to a direct AST check/traversal to find where to start tracking fields
  • Add a case where destructuring is missing to cover result and [result] structures (as commonly returned by hooks)
  • Keep the current method of traversing directly as a fallback case
  • Fix cases where crawlScope wasn't unwrapping destructuring patterns
  • Track functions when they're passed by reference to array methods

Copy link

changeset-bot bot commented Feb 23, 2024

🦋 Changeset detected

Latest commit: cd99244

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

This PR includes changesets to release 1 package
Name Type
@0no-co/graphqlsp Minor

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

@JoviDeCroock JoviDeCroock merged commit b73201e into main Feb 23, 2024
@JoviDeCroock JoviDeCroock deleted the feat/expand-unused-fields-support branch February 23, 2024 14:26
@github-actions github-actions bot mentioned this pull request Feb 23, 2024
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.

Build support for tanstack-query in unused-fields Graphql properties in use are being marked as unused
2 participants