Skip to content

Instantly share code, notes, and snippets.

@DSchau
Created July 17, 2019 18:46
Show Gist options
  • Save DSchau/21518b50f8737b5f494d04cd70bbf806 to your computer and use it in GitHub Desktop.
Save DSchau/21518b50f8737b5f494d04cd70bbf806 to your computer and use it in GitHub Desktop.
Webhook Data from Gatsby Cloud
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