-
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
feat(gatsby): Allow awaiting API run triggered by createNode action #12748
Conversation
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.
In my opinion, this looks great!
I just have a question if you could elaborate on
When the createNode action is called, we currently have no way of knowing when subsequent onCreateNode API calls have finished. This is e.g. a problem in custom field resolvers, where we cannot safely call createRemoteFileNode.
why can't we safely call createRemoteFileNode?
Currently the The problem is that when we call |
Anything missing from this? |
Thinking this looks good--let's get this merged today? |
@pieh want to take a look at this soon? |
Yes, on it. |
I just verified using this simple snippet: ---
title: Hello World
date: "2015-05-01T22:12:03.284Z"
remoteURL: "https://images.unsplash.com/photo-1556379092-dca659792591"
--- exports.sourceNodes = ({ actions, schema, store, cache, createNodeId }) => {
actions.createTypes(`
type MarkdownRemark implements Node {
frontmatter: Frontmatter
}
`)
actions.createTypes(
schema.buildObjectType({
name: "Frontmatter",
fields: {
remoteURL: {
type: `File`,
resolve: async (source, args, context, info) => {
const fieldValue = source[info.fieldName]
console.log({ fieldValue })
const fileNode = await createRemoteFileNode({
url: fieldValue,
store,
cache,
createNode: actions.createNode,
createNodeId,
ext: `.jpg`,
})
return fileNode
},
},
},
})
)
} that this indeed works as expected. We will need to look at bumping/adjusting query running concurrency later on (because using above will limit downloading files to be just from 4 queries, and this can be bottleneck). Will run few more tests (against our .org and few other sites to verify there isn't any unintentional breakage somewhere, but code LGTM |
Also additional note - (not a blocker) - right now, fact that |
Co-Authored-By: stefanprobst <stefan.probst@univie.ac.at>
yes good point! |
Added short note about the returned Promise |
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.
LGTM
When the
createNode
action is called, we currently have no way of knowing when subsequentonCreateNode
API calls have finished. This is e.g. a problem in custom field resolvers, where we cannot safely callcreateRemoteFileNode
.This PR makes
createNode
a thunk which still synchronously dispatches the actions, but returns a Promise of the triggered API run that can optionally be awaited.