-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
extend require-description lint with operation field definitions #1303
Conversation
🦋 Changeset detectedLatest commit: 379ace3 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 |
Thanks for doing this |
Co-authored-by: Victor Rojas <Victorrent@users.noreply.github.com>
Thanks for working on it! I definitely see the benefit of the new option, and will review it soon! |
@@ -147,6 +162,10 @@ const rule: GraphQLESLintRule<[RequireDescriptionRuleConfig]> = { | |||
} | |||
} | |||
|
|||
if (operationFieldDefinition) { | |||
kinds.add(':matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/Query|Mutation|Subscription/] > FieldDefinition'); |
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.
this will not work for root types that are named differently.
example:
type MyQuery {
user: User
}
schema {
query: MyQuery
}
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.
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.
These have been added, but they're hardcoded to avoid requiring the schema for the whole rule. If you'd rather these not be hardcoded and to match no-root-type
's dynamic fetching of the names, I'd be happy to convert this rule so that the schema is exposed to it.
{ | ||
code: 'type Query { users: [User!]! }', | ||
options: [{ operationFieldDefinition: true }], | ||
errors: [{ message: 'Description is required for `Query.users`.' }], | ||
}, |
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.
{ | |
code: 'type Query { users: [User!]! }', | |
options: [{ operationFieldDefinition: true }], | |
errors: [{ message: 'Description is required for `Query.users`.' }], | |
}, |
one test for Query
is enough, instead include 1 test with a root type that is named differently than Query
/Mutation
or Subscription
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.
@B2o5T I added a test case for a root type with a field as a Correct case. Is this what you had in mind? If I misread you I'd be happy to try again
…ns within `Query`, `Mutation`, and `Subscription` root types
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, will be a part of next release
* require description for operation field definitions * Update packages/plugin/tests/require-description.spec.ts Co-authored-by: Victor Rojas <Victorrent@users.noreply.github.com> * narrow query * pr feedback * format * [require-description] add `rootField` option for only field definitions within `Query`, `Mutation`, and `Subscription` root types Co-authored-by: Victor Rojas <Victorrent@users.noreply.github.com> Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
Description
This change extends the
require-description
lint to require a description of operations.The field definition within the operation types is tricky to target. A description isn't required for every
Kind.FIELD_DEFINITION
so the existing feature would've involved excessive documentation. Since good code health could require documentation of usable operations, the lint was extended to target field definitions only within the scope ofMutation
,Query
, andSubscription
.This adds the boolean option
operationFieldDefinition
torequire-description
(default false).Type of change
Please delete options that are not relevant.
How Has This Been Tested?
I added two valid unit tests and two invalid unit tests. They cover when an input is present and when an input is not present.
Both unit tests are within the
require-description.spec.ts
fileTest Environment:
@graphql-eslint/...
: master?Checklist:
CONTRIBUTING doc and the
style guidelines of this project