fix: future-proof functionality through Gatsby schema customization #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
Update the node augmentation logic to fall in line with the direction Gatsby is heading (i.e. remove direct node manipulation) to prevent immediate and future breakage.
Closes #28
How
Use Gatsby schema customization (
createResolvers
) to augment the user-supplied node type by adding a field with a user-supplied name where the resolver for said field returns aFile
node created bycreateRemoteFileNode
(fromgatsby-source-filesystem
).Notes
💥 This bumps the required Gatsby peer dependency to
2.2.0
or greater, as that is when the new schema customization APIs were introduced. Not a huge deal, as it has been out since March of 2019, but it is a breaking change and (IMHO) warrants a v2.0.0 release of this plugin.💡 I didn't see a slick way to communicate between the
onCreateNode
API and thecreateResolvers
API, so I introduced a module-level variable to track the relationship between the node to be augmented and the corresponding dynamically created (remote)File
node. It felt a little weird, but it works. One alternative could be a "hidden" (undocumented) plugin option as both API methods get those passed in, but that felt ever stranger.🔧 As the new
File
nodes are no longer being directly injected into the source/parent nodes, the previously existing tests were no longer able to verify the correctFile
node was present. In some cases, I adapted them to just ensure things were being called with the appropriate parameters and in other cases I simply removed the node verification assertion. It's not ideal and I suspect they can be improved, but it's better than nothing. A follow-up PR or suggestions to improve them would be great.