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

gatsby: Remove deprecation warnings for touchNode/deleteNode #33286

Merged
merged 4 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions packages/gatsby/src/datastore/__tests__/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,6 @@ describe(`nodes db tests`, () => {
store.dispatch({ type: `DELETE_CACHE` })
})

it(`warns when using old touchNode 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.touchNode(
{ nodeId: `hi` },
{
name: `tests`,
}
)
)
expect(getNode(`hi`)).toBeDefined()
const deprecationNotice =
`Calling "touchNode" with an object containing the nodeId is deprecated. Please pass ` +
`the node directly to the function: touchNode(node) ` +
`"touchNode" was called by tests`
expect(report.warn).toHaveBeenCalledWith(deprecationNotice)
})

it(`deletes previously transformed children nodes when the parent node is updated`, async () => {
store.dispatch(
actions.createNode(
Expand Down Expand Up @@ -341,40 +307,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(
{ node: getNode(`hi`) },
{
name: `tests`,
}
)
)
expect(getNode(`hi`)).toBeUndefined()
const deprecationNotice =
`Calling "deleteNode" with {node} is deprecated. Please pass ` +
`the node directly to the function: 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 Down
9 changes: 6 additions & 3 deletions packages/gatsby/src/query/__tests__/data-tracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,8 @@ describe(`query caching between builds`, () => {
})
}
if (stage === `delete-foo`) {
nodeApiContext.actions.deleteNode({ node: { id: `foo-1` } })
const node = { id: `foo-1` }
nodeApiContext.actions.deleteNode(node)
}
if (stage === `add-bar2`) {
createBarNode({
Expand All @@ -1368,10 +1369,12 @@ describe(`query caching between builds`, () => {
})
}
if (stage === `delete-bar2`) {
nodeApiContext.actions.deleteNode({ node: { id: `bar-2` } })
const node = { id: `bar-2` }
nodeApiContext.actions.deleteNode(node)
}
if (stage === `delete-bar1`) {
nodeApiContext.actions.deleteNode({ node: { id: `bar-1` } })
const node = { id: `bar-1` }
nodeApiContext.actions.deleteNode(node)
}
},
createPages: ({ actions: { createPage } }, _pluginOptions) => {
Expand Down
2 changes: 2 additions & 0 deletions packages/gatsby/src/redux/__tests__/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { actions } from "../actions"
import { store } from "../index"
import { nodesReducer } from "../reducers/nodes"
import { IGatsbyNode } from "../types"
import { nodesTouchedReducer } from "../reducers/nodes-touched"
Expand All @@ -18,6 +19,7 @@ const fromMapToObject = (map: Map<string, any>): MapObject => {
describe(`Create and update nodes`, (): void => {
beforeEach((): void => {
dispatch.mockClear()
store.dispatch({ type: `DELETE_CACHE` })
})

it(`allows creating nodes`, (): void => {
Expand Down
39 changes: 1 addition & 38 deletions packages/gatsby/src/redux/actions/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,26 +532,7 @@ const deleteNodeDeprecationWarningDisplayedMessages = new Set()
* deleteNode(node)
*/
actions.deleteNode = (node: any, plugin?: Plugin) => {
let id

// TODO(v4): Remove this deprecation warning and only allow deleteNode(node)
if (node && node.node) {
let msg =
`Calling "deleteNode" with {node} is deprecated. Please pass ` +
`the node directly to the function: deleteNode(node)`

if (plugin && plugin.name) {
msg = msg + ` "deleteNode" was called by ${plugin.name}`
}
if (!deleteNodeDeprecationWarningDisplayedMessages.has(msg)) {
report.warn(msg)
deleteNodeDeprecationWarningDisplayedMessages.add(msg)
}

id = node.node.id
} else {
id = node && node.id
}
const id = node && node.id

// Always get node from the store, as the node we get as an arg
// might already have been deleted.
Expand Down Expand Up @@ -925,24 +906,6 @@ const touchNodeDeprecationWarningDisplayedMessages = new Set()
* touchNode(node)
*/
actions.touchNode = (node: any, plugin?: Plugin) => {
// TODO(v4): Remove this deprecation warning and only allow touchNode(node)
if (node && node.nodeId) {
let msg =
`Calling "touchNode" with an object containing the nodeId is deprecated. Please pass ` +
`the node directly to the function: touchNode(node)`

if (plugin && plugin.name) {
msg = msg + ` "touchNode" was called by ${plugin.name}`
}

if (!touchNodeDeprecationWarningDisplayedMessages.has(msg)) {
report.warn(msg)
touchNodeDeprecationWarningDisplayedMessages.add(msg)
}

node = getNode(node.nodeId)
}

if (node && !typeOwners[node.internal.type]) {
typeOwners[node.internal.type] = node.internal.owner
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/schema/infer/__tests__/infer.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const addNodes = nodes => {

const deleteNodes = nodes => {
nodes.forEach(node => {
store.dispatch(actions.deleteNode({ node }, { name: `test` }))
store.dispatch(actions.deleteNode(node, { name: `test` }))
})
}

Expand Down