-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat: track unused fields #146
Conversation
🦋 Changeset detectedLatest commit: a07d830 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 |
4f1aaab
to
7e0b809
Compare
7e0b809
to
ba5576e
Compare
ba5576e
to
54556fb
Compare
4548a86
to
3fba38a
Compare
@@ -40,6 +42,7 @@ export const SEMANTIC_DIAGNOSTIC_CODE = 52001; | |||
export const MISSING_OPERATION_NAME_CODE = 52002; | |||
export const MISSING_FRAGMENT_CODE = 52003; | |||
export const USING_DEPRECATED_FIELD_CODE = 52004; | |||
export const UNUSED_FIELD_CODE = 52005; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: why do these start at 52k? (just curious)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No particular reason, hoping for no clashes 😅 if tsserver
ever reliably allows us to call into the code-fixes
we could use these to i.e. add the missing fragment import, remove the unused fields, replace the deprecated field if we find a use instead
, ...
Resolves #143
Summary
When we are dealing with co-located fragments and operations it can be hard to determine when a field isn't used, especially as your component grows. This tries to prevent that by for
queries
andfragments
implementing basic tracking of aresult
obtained from either of the following waysconst data = useFragment()
||const data = await client.query()
const [result] = useQuery()
--> urqlconst { data } = useQuery()
--> Apollo-clientconst { data: { pokemon } } = useQuery();
const { name } = useFragment()
const [{ data }] = useQuery()
I still need to add tests for this whole ordeal and clean up the code as we can probably simplify this by combining both the crawling steps
When people are missing a fragment in a sub-component like
Then it will show name and fleeRate as unused as we expect this to be part of the fragment exported by
Pokemon
.Notes
We don't track mutations/subscriptions due to how they might be getting used in the normalised cache updaters/...
We don't resolve fragments as we make the assumption that those come from external components so we won't tell you that a fragment/... is unused