Skip to content

Instantly share code, notes, and snippets.

@vladar
Last active July 10, 2020 07:27
Show Gist options
  • Save vladar/d7659285b7292cde011687939e158d6a to your computer and use it in GitHub Desktop.
Save vladar/d7659285b7292cde011687939e158d6a to your computer and use it in GitHub Desktop.
exports.sourceNodes = async (gatsbyAPI, pluginOptions) => {
const config = await createSourcingConfig(gatsbyApi)
const { webhookBody } = gatsbyAPI
if (webhookBody && Object.keys(webhookBody).length) {
const { isDelete, typeName, id } = webhookBody
const nodeEvent = isDelete
? {
eventName: "DELETE",
remoteTypeName: typeName,
remoteId: { __typename: typeName, id },
}
: {
eventName: "UPDATE",
remoteTypeName: typeName,
remoteId: { __typename: typeName, id },
}
await sourceNodeChanges(config, { nodeEvents: [nodeEvent] })
} else {
// Normal full sourcing
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment