-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
fix(gatsby): print childOf directive for implicit child fields #28483
Conversation
257499f
to
4d7f4b3
Compare
childOfExtension = { types: [] } | ||
} | ||
childOfExtension.types.push(parentTypeName) | ||
childTypeComposer.setExtension(`childOf`, childOfExtension) |
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.
The essence of this PR: instead of adding fields directly we add the childOf
directive here. And fields are always added in a single place now - where this directive is processed (in addConvenienceChildrenFields
):
gatsby/packages/gatsby/src/schema/schema.js
Lines 972 to 975 in 76a3b57
children.forEach(child => { | |
typeComposer.addFields(createChildrenField(child.getTypeName())) | |
typeComposer.addFields(createChildField(child.getTypeName())) | |
}) |
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.
Looks great! That was quite a journey to get to this point (including other PR(s) on the way heh and possibly some ahead (weird behaviour of update
option on schema snapshot plugin ;) ).
Let's get this in!
Description
Fixes a bug with schema printing of inferred
childOf
directive. Before this PR if we print a schema with infered child fields (e.g.File.childImageSharp
) it won't includechildOf
directive:After this PR it correctly prints this:
This fixed variant will correctly wotk in Gatsby v3. The variant before this PR will fail to work in Gatsby v3 (the printed schema snapshot won't add the
File.childImageSharp
field).Potentially a breaking change :/Worked around breaking change via #28656
See details (no longer actual)
Requires a bit of investigation. To illustrate a possible break. With this change, we automatically apply the `childOf` extension (instead of inferring child fields):The
many
argument here is what is problematic. Before this change (with simple inference) we could get these two types (at least theoretically):so in one case - singular
Bar.childFoo
in the other case - arrayBaz.childrenFoo
. After this change, we will always have both singular or both arrays. Mixing is not allowed with this directive.The
many
argument applies to all parent types. Not sure if it is intentional or an oversight.Ways to fix this
Suggested by @pieh : Always add both
child{Field}
andchildren{Field}
to the schema and deprecatemany
option altogether. Wih this changechild{Field}
will always return the first child (as listed in nodechildren
array)Support the new syntax in
childOf
directive where we can definemany
per type. Something like:Related issues
Fixes #19674