-
Notifications
You must be signed in to change notification settings - Fork 47
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
[unused-fields] Add option to check leave fields only #95
base: main
Are you sure you want to change the base?
Conversation
+1, we have the same problem. We'd like to use a helper to extract nodes from a connection and it generates false positives. The reasoning seems sound - if leaves are being used then the intermediary nodes are being used implicitly, even if the code can't detect it reliably. It would be great if this could get merged. |
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.
very common pattern
{ | ||
code: ` | ||
graphql\`fragment Test on Page { unused1 { unused2 } }\`; | ||
`, | ||
options: [{leavesOnly: true}], | ||
errors: [unusedFieldsWarning('unused2')] | ||
}, |
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.
does it works well if we use options, for some reason, as [{leavesOnly: true}, ignoreFields: ['unsed2']]
?
I think that can add a new test
{
code: `
graphql\`fragment Test on Page { unused1 { unused2 } }\`;
`,
options: [{leavesOnly: true}, ignoreFields: ['unsed2']],
},
Builds on top of #94 for option parsing code. Check commit 8d0773f only.
Motivation
This makes it so we only check leave fields, I'm not sure if there is actually cases where checking non-leaves is useful, so I left it as an option. If there are not we could make this the default. There are cases where non leave fields are never accessed because of helper functions in other files.
For example I use a
useConnectionArray
hook to transform a connection to an array. This will currently trigger the unused field rule since the current file never accessesedges
andnode
.Example:
Test plan
Tested on a large relay codebase and added tests.