-
Notifications
You must be signed in to change notification settings - Fork 10.3k
fix(gatsby-source-contentful): fix downloadLocal for LMDB #33715
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
Conversation
|
There are failing unit tests here, that I can fix, but this PR is mostly "concept" - I don't know if it's best way to implement downloading assets before creating nodes, I just did "massage" code to fit it |
|
Other alternative than this approach is to keep most of it as is and just not mutate node in
createNodeField + schema customization so that localFile seems to be working the same to users - will explore that in a bit
|
|
I'll have a look tomorrow |
|
Not sure if this will be helpful, but the change in this PR now is very similar to updated docs (not yet merged in #33720 ) that is meant for easier migration than what I initially had (which was also "correct" in sense that would work, just shuffled so much code around that it was making review much more difficult) |
a348995 to
9e56216
Compare
* fix(gatsby-source-contentful): fix downloadLocal for LMDB * Revert "fix(gatsby-source-contentful): fix downloadLocal for LMDB" This reverts commit 5bacca7. * use createNodeField + schemaCustomization * tests: add downloadLocal to e2e tests * fix unit tests after removal of pre bootstrap Co-authored-by: axe312ger <opensource@axe312.dev>
Description
In v4 (or with LMDB rather as this does apply to v3 with LMDB/PQR experiments enabled) mutating nodes after they are created is no longer working (even before while it was "working" it often caused a lot of problems and was antipattern that could cause difficult to debug problems).
Right now when
downloadLocaloption is used in Contentful plugin, it actually does try to mutate node after it was created resulting inlocalFilejust not being there anymore (even tho files are still downloaded).This PR instead of mutating node directly, use
createNodeFieldto add data in Gatsby friendly way to a node (that works with LMDB). And then use schema customization so thelocalFileremains on root level of the "node" in GraphQL (so no breaking changes)We do have note about this problem in migration https://v4.gatsbyjs.com/docs/reference/release-notes/migrating-from-v3-to-v4/#dont-mutate-nodes-outside-of-expected-apis but
Makes it really hard for users or plugin authors to actually catch that. This will likely have follow ups to actually do add ways of automatic detection (maybe in diagnostic mode, or maybe some heuristics that checks just subset of nodes or combination of both). https://github.com/gatsbyjs/gatsby/compare/node-mutations-are-a-no-no has potential detection, but not benchmarked yet (but at least it allowed me to catch the problem here)