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
Next Next commit
remove nodeId as arg
  • Loading branch information
LekoArts committed Jan 26, 2021
commit 106c2d56f1c042d684df9ca7737fbfd30c0ef6f1
40 changes: 6 additions & 34 deletions packages/gatsby/src/db/__tests__/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,37 +317,6 @@ describe(`nodes db tests`, () => {
expect(getNode(`hi`)).toBeUndefined()
})

it(`warns when using old deleteNode signature `, () => {
store.dispatch(
actions.createNode(
{
id: `hi`,
children: [],
parent: `test`,
internal: {
contentDigest: `hasdfljds`,
type: `Test`,
},
},
{
name: `tests`,
}
)
)
expect(getNode(`hi`)).toMatchObject({ id: `hi` })
store.dispatch(
actions.deleteNode(`hi`, getNode(`hi`), {
name: `tests`,
})
)
expect(getNode(`hi`)).toBeUndefined()
const deprecationNotice =
`Calling "deleteNode" with a nodeId is deprecated. Please pass an ` +
`object containing a full node instead: deleteNode({ node }). ` +
`"deleteNode" was called by tests`
expect(report.warn).toHaveBeenCalledWith(deprecationNotice)
})

it(`throws an error when trying to delete a node of a type owned from another plugin`, () => {
expect(() => {
store.dispatch(
Expand All @@ -367,9 +336,12 @@ describe(`nodes db tests`, () => {
)
)
store.dispatch(
actions.deleteNode(`hi`, getNode(`hi`), {
name: `tests`,
})
actions.deleteNode(
{ node: getNode(`hi`) },
{
name: `tests`,
}
)
)
}).toThrow(/deleted/)
})
Expand Down
22 changes: 2 additions & 20 deletions packages/gatsby/src/redux/actions/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,26 +430,8 @@ ${reservedFields.map(f => ` * "${f}"`).join(`\n`)}
* @example
* deleteNode({node: node})
*/
actions.deleteNode = (options: any, plugin: Plugin, args: any) => {
let id

// Check if using old method signature. Warn about incorrect usage but get
// node from nodeID anyway.
if (typeof options === `string`) {
let msg =
`Calling "deleteNode" with a nodeId is deprecated. Please pass an ` +
`object containing a full node instead: deleteNode({ node }).`
if (args && args.name) {
// `plugin` used to be the third argument
plugin = args
msg = msg + ` "deleteNode" was called by ${plugin.name}`
}
report.warn(msg)

id = options
} else {
id = options && options.node && options.node.id
}
actions.deleteNode = (options: any, plugin: Plugin) => {
const id = options && options.node && options.node.id

// Always get node from the store, as the node we get as an arg
// might already have been deleted.
Expand Down