-
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
docs(gatsby-source-wordpress): Remove lodash + bluebird + fix Promise hell #11739
Conversation
This commit: - Removes lodash in favor of Array.forEach - Bluebird in favor of the native Promise object - Avoids nested thenables by using Promise.all() I've been using this code in my builds and it's been working fine for whatever that worth :)
Looks like the Azure Pipeline task has a bug pulling something with Yarn, but the code works otherwise 😱
|
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.
Yeah - this is generally cleaner.
Would you be interested in refactoring with async/await? (see #11548 for more info on that!)
I initially had an async/await version but decided on this approach as Promise.all() should be faster as both Promises execute in parallel this way :D |
@DylanTackoor you can (and should!) use Promise.all with async/await ;) Using one does not preclude the other. |
Sweet, thanks for the tip! I'll update the PR later today when I have a chance 😊 |
Feeling like this is a bit cleaner than the Promise.all() approach :)
@DSchau I ended up avoiding using Promise.all() in favor of a single async GraphQL query. Thoughts? |
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.
Looking better!
Unfortunately, we don't throw errors if a GraphQL query has errors (so you can still use the GraphiQL editor to try and debug queries), we use an errors
property on the returned object from the graphql call.
So you'll want to remove the try/catch, and rather do something like
const result = await graphql(``)
if (result.errors) {
throw new Error(result.errors)
}
if you want to stop execution and alert of errors.
Moved from try/catch to checking if results.errors exits
Fixed it! Also took the chance to destructure the data property. |
Merged master and ran prettier @DSchau mind taking another look? |
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.
Let's do it; thanks for this, think it's a big improvement! Also co-locating the queries instead of a Promise.all was a nice tweak!
Holy buckets, @DylanTackoor — we just merged your PR to Gatsby! 💪💜 Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! |
<!-- Have any questions? Check out the contributing docs at https://gatsby.app/contribute, or ask in this Pull Request and a Gatsby maintainer will be happy to help :) --> ## Description Updates example site gatsby-node.js to match documentation. ## Related Issues Previously implemented in #11739.
Description
This commit:
I've been using this code in my builds and it's been working fine for whatever that worth :)