Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
required-fields: inline fragments without a field ancestor (#240)
We are planning to use the `required-fields` rule to enforce the `id` field but we have some code that was causing `TypeError: Cannot read property 'selectionSet' of undefined` errors. I tracked down the issue to the case where an inline fragment is missing a required field but does not have a field ancestor. The existing code for the rule will walk up the ancestors until it finds a field, but an inline fragment can be part of any selection set and not only a field (in our case a fragment definition). This example based on the unit tests should demonstrate the issue: ```graphql fragment GreetingOrStoryFragment on GreetingOrStory { ... on Greetings { hello } } ``` The `id` field is missing from the inline fragment My fix was just to walk up the ancestors until it fields the first field, operation definition or fragment definition. It basically stops when it finds something that contains a selection set with the exception of an inline fragment, which we intentionally keep walking up. TODO: - [x] Make sure all of the significant new logic is covered by tests - [x] Rebase your changes on master so that they can be merged easily - [x] Make sure all tests pass - [x] Update CHANGELOG.md with your change - [x] If this was a change that affects the external API, update the README
- Loading branch information
1 parent
d9aa7a4
commit 8249202
Showing
3 changed files
with
29 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters