-
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: inline fragments without a field ancestor #240
Conversation
11ef5f3
to
db27602
Compare
Looks like the build is failing for unrelated reasons. cc @jnwng |
…ql into hqd/fragment-fix
Build is now passing. Let me know if there is anything I can do for this PR. Thanks! |
Could this please get merged? We are running into the same problems |
208140f
to
ecbb061
Compare
I just added some valid cases to the One thing I noticed is that |
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 adding the test cases @henryqdineen!
live in |
Thanks Jon! |
We are planning to use the
required-fields
rule to enforce theid
field but we have some code that was causingTypeError: 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:
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: