Skip to content
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): Remove deleteNode with ID arg #29205

Merged
merged 10 commits into from
Feb 10, 2021
Prev Previous commit
Next Next commit
update deleteNode usage in our code
  • Loading branch information
LekoArts committed Jan 27, 2021
commit 2652407ebe15cdbfd22f295caa600a999957952b
6 changes: 2 additions & 4 deletions docs/docs/creating-a-source-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ exports.createSchemaCustomization = ({ actions }) => {
author: Author @link(from: "author.name" by: "name") // highlight-line
# ... other fields
}

type Author implements Node {
name: String!
post: Post @link // highlight-line
Expand Down Expand Up @@ -446,9 +446,7 @@ exports.sourceNodes = async ({ actions, getNodesByType }, pluginOptions) => {
newData.forEach(newDatum => {
switch (newDatum.status) {
case "deleted":
deleteNode({
node: getNode(createNodeId(`YourSourceType-${newDatum.uuid}`)),
})
deleteNode(getNode(createNodeId(`YourSourceType-${newDatum.uuid}`)))
break
case "created":
case "updated":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,7 @@ exports.sourceNodes = async (
const nodeId = createNodeId(`${POST_NODE_TYPE}-${post.id}`)
switch (post.status) {
case "deleted":
deleteNode({
node: getNode(nodeId),
})
deleteNode(getNode(nodeId))
break
case "created":
case "updated":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ exports.sourceNodes = async function sourceNodes({
deleted.forEach(node => {
const existing = getNode(node.id)
if (existing) {
deleteNode({
node: existing,
})
deleteNode(existing)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ exports.sourceNodes = async function sourceNodes({
deleted.forEach(node => {
const existing = getNode(node.id)
if (existing) {
deleteNode({
node: existing,
})
deleteNode(existing)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ exports.sourceNodes = async function sourceNodes(
const nodeId = createNodeId(`${POST_NODE_TYPE}-${post.id}`)
switch (post.status) {
case "deleted":
deleteNode({
node: getNode(nodeId),
})
deleteNode(getNode(nodeId))
break
case "created":
case "updated":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ describe(`gatsby-node`, () => {
// don't allow mutations (this isn't traversing so only top level is frozen)
currentNodeMap.set(node.id, Object.freeze(node))
})
actions.deleteNode = ({ node }) => {
actions.deleteNode = node => {
currentNodeMap.delete(node.id)
}
actions.touchNode = jest.fn()
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-contentful/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ exports.sourceNodes = async (
localizedNodes.forEach(node => {
// touchNode first, to populate typeOwners & avoid erroring
touchNode({ nodeId: node.id })
deleteNode({ node })
deleteNode(node)
})
}

Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby-source-drupal/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ exports.sourceNodes = async (
return
}
if (action === `delete`) {
actions.deleteNode({ node: getNode(createNodeId(id)) })
actions.deleteNode(getNode(createNodeId(id)))
reporter.log(`Deleted node: ${id}`)
changesActivity.end()
return
Expand Down Expand Up @@ -147,7 +147,7 @@ exports.sourceNodes = async (
let nodesToSync = data.data.entities
for (const nodeSyncData of nodesToSync) {
if (nodeSyncData.action === `delete`) {
actions.deleteNode({ node: getNode(createNodeId(nodeSyncData.id)) })
actions.deleteNode(getNode(createNodeId(nodeSyncData.id)))
} else {
// The data could be a single Drupal entity or an array of Drupal
// entities to update.
Expand Down Expand Up @@ -385,7 +385,7 @@ exports.onCreateDevServer = (
)
}
if (action === `delete`) {
actions.deleteNode({ node: getNode(createNodeId(id)) })
actions.deleteNode(getNode(createNodeId(id)))
return reporter.log(`Deleted node: ${id}`)
}
const nodeToUpdate = JSON.parse(JSON.parse(req.body)).data
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-filesystem/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const createFSMachine = (
// It's possible the node was never created as sometimes tools will
// write and then immediately delete temporary files to the file system.
if (node) {
deleteNode({ node })
deleteNode(node)
}
}

Expand Down
7 changes: 1 addition & 6 deletions packages/gatsby/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,10 +1110,6 @@ interface ActionPlugin {
name: string
}

interface DeleteNodeArgs {
node: Node
}

interface CreateNodeFieldArgs {
node: Node
name: string
Expand Down Expand Up @@ -1157,9 +1153,8 @@ export interface Actions {

/** @see https://www.gatsbyjs.org/docs/actions/#deletePage */
deleteNode(
options: { node: Node },
node: NodeInput,
plugin?: ActionPlugin,
option?: ActionOptions
): void

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,5 @@ exports.onCreatePage = ({ createContentDigest, page, actions }) => {
emitter.on(`DELETE_PAGE`, action => {
const nodeId = createPageId(action.payload.path)
const node = getNode(nodeId)
boundActionCreators.deleteNode({ node })
boundActionCreators.deleteNode(node)
})
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/source-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function deleteStaleNodes(state: IGatsbyState, nodes: Array<Node>): void {
const staleNodes = getStaleNodes(state, nodes)

if (staleNodes.length > 0) {
staleNodes.forEach(node => deleteNode({ node }))
staleNodes.forEach(node => deleteNode(node))
}
}

Expand Down