-
Notifications
You must be signed in to change notification settings - Fork 106
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
Add require-import-fragment
rule
#1443
Add require-import-fragment
rule
#1443
Conversation
🦋 Changeset detectedLatest commit: 007cbf3 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 |
also, what will happen if you import # import Foo from 'not-foo.graphql'
query MyQuery {
fooField {
...Foo
}
} |
Co-authored-by: Dimitri POSTOLOV <[email protected]>
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.
That looks really good, thank you!
'FragmentSpread .name'(node: GraphQLESTreeNode<NameNode>) { | ||
fragmentSpreadNameNodes.add(node); | ||
}, | ||
FragmentDefinition(fragmentDefinitionNode) { | ||
knownFragmentNames.add(fragmentDefinitionNode.name.value); | ||
'FragmentDefinition .name'(node: GraphQLESTreeNode<NameNode>) { |
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.
Why .name
and not just Name
?
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.
it is because FragmentDefinition Name
will match
// some abstract GraphQL AST Node
const node = {
type: 'FragmentDefinition',
name: { // ✅ matched 1
type: 'Name'
// ...
},
foo: { // ✅ matched 2
type: 'Name',
bar: { // ✅ matched 3
type: 'Name'
// ...
}
// ...
}
// ...
}
FragmentDefinition .name
will match onlynode.name
FragmentDefinition > Name
will match onlynode.name
andnode.foo
but notnot.foo.bar
So for more safety, it should be FragmentDefinition > .name
, I remember I got some issue due too wide
selector, so it's better to be explicit while selecting nodes
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.
thanks for working on it! In case you would work on other rules you could extract some pieces of code for parsing#import
comments!
Description
Fixes #1413
Type of change
How Has This Been Tested?
Via unit tests (see changed files).
Test Environment:
Checklist:
CONTRIBUTING doc and the
style guidelines of this project