-
Notifications
You must be signed in to change notification settings - Fork 103
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
Required fields and fragments #199
Conversation
…laar/eslint-plugin-graphql into stevehollaar-require-field-on-parent-2
cc @stevehollaar and @jnwng please give this a look if you have time! My intention is to make this rule a reliable way to ensure that a certain field is fetched ( Open to any ideas that allow more valid combinations of fields, but I'd also rather err on the conservative side. |
cc @hellendag |
CHANGELOG.md
Outdated
- Here's a specific case which is _no longer valid_: | ||
- `query { greetings { hello ... on Greetings { id } } }` | ||
- This must now be written as `query { greetings { id hello ... on Greetings { id } } }` | ||
- This is a more convervative approach than before, driven by the fact that it's quite hard to ensure that a combination of inline fragments actually covers all of the possible types of a selection set. |
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.
nit: typo at "convervative"?
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 reviewing!
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.
🙌
type: "TaggedTemplateExpression" | ||
} | ||
] | ||
}, |
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.
Also worth testing an interface where id
is a shared field?
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.
Done!
CHANGELOG.md
Outdated
@@ -1,5 +1,13 @@ | |||
# Change log | |||
### vNEXT | |||
- BREAKING: The `required-fields` rule has been significantly changed to make it a completely reliable method of ensuring `id` fields are always requested when available. [PR #199](https://github.com/apollographql/eslint-plugin-graphql/pull/199) Here is the behavior, let's say we are requiring field `x`: | |||
- On any field whose return type defines a field called `x`, the selection set must directly contain `x`. |
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.
x
is a bit of an odd example field name. :D
src/customGraphQLValidationRules.js
Outdated
}); | ||
}, | ||
|
||
// Every inline fragment must have an ID specified inside itself or in some |
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.
s/an ID
/the required field
(Waiting on an OK from @jnwng about whether this breaking change is fine) |
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.
lgtm — this should definitely be a major bump
Published as 3.0.0! |
TODO:
Pull Request Labels