Created
July 17, 2019 18:46
-
-
Save DSchau/21518b50f8737b5f494d04cd70bbf806 to your computer and use it in GitHub Desktop.
Webhook Data from Gatsby Cloud
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.sourceNodes = async function sourceNodes({ actions, webhookBody }) { | |
/* | |
* Note: this is the webhook body that is passed from | |
* your CMS -> Gatsby Preview -> this function | |
* It will be a JS object, and you can use this data to "get consistent" | |
* with the remote CMS state | |
* Note: if you have a structure for deletes/creates/updates use it here! | |
*/ | |
if (webhookBody && webhookBody.updates) { | |
await Promise.all( | |
webhookBody.updates.map(update => { | |
// fire off requests, create/touch nodes, etc. | |
}) | |
) | |
} else { | |
/* | |
* Normal flow for plugin; this will be your existing source code | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment