From ac2a54ae6795636d9088a06ac8c26bd1519e3728 Mon Sep 17 00:00:00 2001 From: stefanprobst Date: Tue, 8 Jan 2019 18:36:13 +0100 Subject: [PATCH] chore: use null not "SOURCE" as parent of top level nodes (#10920) --- docs/docs/node-creation.md | 2 +- .../src/create-file-node.js | 2 +- .../__snapshots__/gatsby-node.js.snap | 10 +++++----- .../src/__tests__/gatsby-node.js | 2 +- .../__snapshots__/gatsby-node.js.snap | 18 +++++++++--------- .../src/__tests__/gatsby-node.js | 2 +- .../__snapshots__/gatsby-node.js.snap | 6 +++--- .../src/__tests__/gatsby-node.js | 2 +- .../__snapshots__/gatsby-node.js.snap | 12 ++++++------ .../src/__tests__/gatsby-node.js | 2 +- .../__snapshots__/gatsby-node.js.snap | 2 +- .../src/__tests__/gatsby-node.js | 2 +- .../__snapshots__/gatsby-node.js.snap | 4 ++-- .../src/__tests__/gatsby-node.js | 2 +- .../__snapshots__/gatsby-node.js.snap | 6 +++--- .../src/__tests__/gatsby-node.js | 2 +- .../internal-data-bridge/gatsby-node.js | 8 ++++---- 17 files changed, 42 insertions(+), 42 deletions(-) diff --git a/docs/docs/node-creation.md b/docs/docs/node-creation.md index 6ea9d046f51fe..ffe9679904bbc 100644 --- a/docs/docs/node-creation.md +++ b/docs/docs/node-creation.md @@ -8,7 +8,7 @@ A node is stored in redux under the `nodes` namespace, whose state is a map of t ## Sourcing Nodes -The creation of nodes occurs primarily in the [sourceNodes](/docs/node-apis/#sourceNodes) bootstrap phase. Nodes created during this phase are top level nodes. I.e, they have no parent. This is represented by source plugins setting the node's `parent` field to `___SOURCE___`. Nodes created via transform plugins (who implement [onCreateNode](/docs/node-apis/#onCreateNode)) will have source nodes as their parents, or other transformed nodes. For a rough overview of what happens when source nodes run, see the [traceID illustration](/docs/how-plugins-apis-are-run/#using-traceid-to-await-downstream-api-calls). +The creation of nodes occurs primarily in the [sourceNodes](/docs/node-apis/#sourceNodes) bootstrap phase. Nodes created during this phase are top level nodes. I.e, they have no parent. This is represented by source plugins setting the node's `parent` field to `null`. Nodes created via transform plugins (who implement [onCreateNode](/docs/node-apis/#onCreateNode)) will have source nodes as their parents, or other transformed nodes. For a rough overview of what happens when source nodes run, see the [traceID illustration](/docs/how-plugins-apis-are-run/#using-traceid-to-await-downstream-api-calls). ## Parent/Child/Refs diff --git a/packages/gatsby-source-filesystem/src/create-file-node.js b/packages/gatsby-source-filesystem/src/create-file-node.js index 535620c56200a..3db6fcadd8483 100644 --- a/packages/gatsby-source-filesystem/src/create-file-node.js +++ b/packages/gatsby-source-filesystem/src/create-file-node.js @@ -57,7 +57,7 @@ exports.createFileNode = async ( // useful information. id: createNodeId(pathToFile), children: [], - parent: `___SOURCE___`, + parent: null, internal, sourceInstanceName: pluginOptions.name || `__PROGRAMMATIC__`, absolutePath: slashedFile.absolutePath, diff --git a/packages/gatsby-transformer-csv/src/__tests__/__snapshots__/gatsby-node.js.snap b/packages/gatsby-transformer-csv/src/__tests__/__snapshots__/gatsby-node.js.snap index 876a82914a97d..b42b670c9e4be 100644 --- a/packages/gatsby-transformer-csv/src/__tests__/__snapshots__/gatsby-node.js.snap +++ b/packages/gatsby-transformer-csv/src/__tests__/__snapshots__/gatsby-node.js.snap @@ -58,7 +58,7 @@ false,\\"nope\\"", "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -87,7 +87,7 @@ false,\\"nope\\"", "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -165,7 +165,7 @@ false,nope", "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -194,7 +194,7 @@ false,nope", "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -223,7 +223,7 @@ false,nope", "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], diff --git a/packages/gatsby-transformer-csv/src/__tests__/gatsby-node.js b/packages/gatsby-transformer-csv/src/__tests__/gatsby-node.js index 5cf7bd33dbfac..0dadd5ac6b9f3 100644 --- a/packages/gatsby-transformer-csv/src/__tests__/gatsby-node.js +++ b/packages/gatsby-transformer-csv/src/__tests__/gatsby-node.js @@ -6,7 +6,7 @@ const { onCreateNode } = require(`../gatsby-node`) describe(`Process nodes correctly`, () => { const node = { id: `whatever`, - parent: `SOURCE`, + parent: null, children: [], extension: `csv`, internal: { diff --git a/packages/gatsby-transformer-excel/src/__tests__/__snapshots__/gatsby-node.js.snap b/packages/gatsby-transformer-excel/src/__tests__/__snapshots__/gatsby-node.js.snap index 6a7d83c0e7e02..5c31be92a58dd 100644 --- a/packages/gatsby-transformer-excel/src/__tests__/__snapshots__/gatsby-node.js.snap +++ b/packages/gatsby-transformer-excel/src/__tests__/__snapshots__/gatsby-node.js.snap @@ -70,7 +70,7 @@ FALSE,nope "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -100,7 +100,7 @@ FALSE,nope "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -128,7 +128,7 @@ FALSE,nope "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -205,7 +205,7 @@ FALSE,nada "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -235,7 +235,7 @@ FALSE,nada "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -263,7 +263,7 @@ FALSE,nada "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -340,7 +340,7 @@ FALSE,nada "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -370,7 +370,7 @@ FALSE,nada "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -398,7 +398,7 @@ FALSE,nada "mediaType": "text/csv", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], diff --git a/packages/gatsby-transformer-excel/src/__tests__/gatsby-node.js b/packages/gatsby-transformer-excel/src/__tests__/gatsby-node.js index ba878f2429394..00ccf2b0e50ce 100644 --- a/packages/gatsby-transformer-excel/src/__tests__/gatsby-node.js +++ b/packages/gatsby-transformer-excel/src/__tests__/gatsby-node.js @@ -6,7 +6,7 @@ const { onCreateNode } = require(`../gatsby-node`) describe(`Process nodes correctly`, () => { const node = { id: `whatever`, - parent: `SOURCE`, + parent: null, children: [], extension: `csv`, internal: { diff --git a/packages/gatsby-transformer-hjson/src/__tests__/__snapshots__/gatsby-node.js.snap b/packages/gatsby-transformer-hjson/src/__tests__/__snapshots__/gatsby-node.js.snap index 874e9cdd8605e..3b3f9c0945aeb 100644 --- a/packages/gatsby-transformer-hjson/src/__tests__/__snapshots__/gatsby-node.js.snap +++ b/packages/gatsby-transformer-hjson/src/__tests__/__snapshots__/gatsby-node.js.snap @@ -48,7 +48,7 @@ Array [ "name": "test", }, "name": "nodeName", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -121,7 +121,7 @@ Array [ "name": "test", }, "name": "nodeName", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -158,7 +158,7 @@ Array [ "name": "test", }, "name": "nodeName", - "parent": "SOURCE", + "parent": null, }, }, ], diff --git a/packages/gatsby-transformer-hjson/src/__tests__/gatsby-node.js b/packages/gatsby-transformer-hjson/src/__tests__/gatsby-node.js index f631ab236f4fd..eccbcb21b434f 100644 --- a/packages/gatsby-transformer-hjson/src/__tests__/gatsby-node.js +++ b/packages/gatsby-transformer-hjson/src/__tests__/gatsby-node.js @@ -7,7 +7,7 @@ describe(`Process HJSON nodes correctly`, () => { const node = { name: `nodeName`, id: `whatever`, - parent: `SOURCE`, + parent: null, children: [], internal: { contentDigest: `whatever`, diff --git a/packages/gatsby-transformer-json/src/__tests__/__snapshots__/gatsby-node.js.snap b/packages/gatsby-transformer-json/src/__tests__/__snapshots__/gatsby-node.js.snap index aac7bfaf3455d..f948c87169a13 100644 --- a/packages/gatsby-transformer-json/src/__tests__/__snapshots__/gatsby-node.js.snap +++ b/packages/gatsby-transformer-json/src/__tests__/__snapshots__/gatsby-node.js.snap @@ -44,7 +44,7 @@ Array [ "type": "File", }, "name": "nodeName", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -93,7 +93,7 @@ Array [ "mediaType": "application/json", "type": "NotFile", }, - "parent": "SOURCE", + "parent": null, }, }, ], @@ -157,7 +157,7 @@ Array [ "type": "File", }, "name": "nodeName", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -185,7 +185,7 @@ Array [ "type": "File", }, "name": "nodeName", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -247,7 +247,7 @@ Array [ "mediaType": "application/json", "type": "NotFile", }, - "parent": "SOURCE", + "parent": null, }, }, ], @@ -273,7 +273,7 @@ Array [ "mediaType": "application/json", "type": "NotFile", }, - "parent": "SOURCE", + "parent": null, }, }, ], diff --git a/packages/gatsby-transformer-json/src/__tests__/gatsby-node.js b/packages/gatsby-transformer-json/src/__tests__/gatsby-node.js index 65cd22546f02e..196f2f22eca22 100644 --- a/packages/gatsby-transformer-json/src/__tests__/gatsby-node.js +++ b/packages/gatsby-transformer-json/src/__tests__/gatsby-node.js @@ -33,7 +33,7 @@ const bootstrapTest = async (node, pluginOptions = {}) => { describe(`Process JSON nodes correctly`, () => { const baseNode = { id: `whatever`, - parent: `SOURCE`, + parent: null, children: [], internal: { contentDigest: `whatever`, diff --git a/packages/gatsby-transformer-toml/src/__tests__/__snapshots__/gatsby-node.js.snap b/packages/gatsby-transformer-toml/src/__tests__/__snapshots__/gatsby-node.js.snap index 2521d1e0dcac2..b6e6833b5375b 100644 --- a/packages/gatsby-transformer-toml/src/__tests__/__snapshots__/gatsby-node.js.snap +++ b/packages/gatsby-transformer-toml/src/__tests__/__snapshots__/gatsby-node.js.snap @@ -97,7 +97,7 @@ Array [ "contentDigest": "whatever", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], diff --git a/packages/gatsby-transformer-toml/src/__tests__/gatsby-node.js b/packages/gatsby-transformer-toml/src/__tests__/gatsby-node.js index e827bfed37104..973f3c6eda227 100644 --- a/packages/gatsby-transformer-toml/src/__tests__/gatsby-node.js +++ b/packages/gatsby-transformer-toml/src/__tests__/gatsby-node.js @@ -3,7 +3,7 @@ const { onCreateNode } = require(`../gatsby-node`) describe(`Process TOML nodes correctly`, () => { const node = { id: `whatever`, - parent: `SOURCE`, + parent: null, children: [], extension: `toml`, internal: { diff --git a/packages/gatsby-transformer-xml/src/__tests__/__snapshots__/gatsby-node.js.snap b/packages/gatsby-transformer-xml/src/__tests__/__snapshots__/gatsby-node.js.snap index c010cf273ace4..9c4cc7d0b7803 100644 --- a/packages/gatsby-transformer-xml/src/__tests__/__snapshots__/gatsby-node.js.snap +++ b/packages/gatsby-transformer-xml/src/__tests__/__snapshots__/gatsby-node.js.snap @@ -206,7 +206,7 @@ Array [ "name": "test", }, "name": "nodeName", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -299,7 +299,7 @@ Array [ "name": "test", }, "name": "nodeName", - "parent": "SOURCE", + "parent": null, }, }, ], diff --git a/packages/gatsby-transformer-xml/src/__tests__/gatsby-node.js b/packages/gatsby-transformer-xml/src/__tests__/gatsby-node.js index a289fa99c1a72..a72947048c67d 100644 --- a/packages/gatsby-transformer-xml/src/__tests__/gatsby-node.js +++ b/packages/gatsby-transformer-xml/src/__tests__/gatsby-node.js @@ -5,7 +5,7 @@ describe(`Process XML nodes correctly`, () => { const node = { name: `nodeName`, id: `whatever`, - parent: `SOURCE`, + parent: null, children: [], internal: { contentDigest: `whatever`, diff --git a/packages/gatsby-transformer-yaml/src/__tests__/__snapshots__/gatsby-node.js.snap b/packages/gatsby-transformer-yaml/src/__tests__/__snapshots__/gatsby-node.js.snap index 7d0aaca4536ed..1947753170918 100644 --- a/packages/gatsby-transformer-yaml/src/__tests__/__snapshots__/gatsby-node.js.snap +++ b/packages/gatsby-transformer-yaml/src/__tests__/__snapshots__/gatsby-node.js.snap @@ -45,7 +45,7 @@ funny: yup "mediaType": "text/yaml", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -111,7 +111,7 @@ Array [ "mediaType": "text/yaml", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], @@ -141,7 +141,7 @@ Array [ "mediaType": "text/yaml", }, "name": "test", - "parent": "SOURCE", + "parent": null, }, }, ], diff --git a/packages/gatsby-transformer-yaml/src/__tests__/gatsby-node.js b/packages/gatsby-transformer-yaml/src/__tests__/gatsby-node.js index a520ff27f3734..e9684ab61fda6 100644 --- a/packages/gatsby-transformer-yaml/src/__tests__/gatsby-node.js +++ b/packages/gatsby-transformer-yaml/src/__tests__/gatsby-node.js @@ -6,7 +6,7 @@ const { onCreateNode } = require(`../gatsby-node`) describe(`Process YAML nodes correctly`, () => { const node = { id: `whatever`, - parent: `SOURCE`, + parent: null, children: [], internal: { contentDigest: `whatever`, diff --git a/packages/gatsby/src/internal-plugins/internal-data-bridge/gatsby-node.js b/packages/gatsby/src/internal-plugins/internal-data-bridge/gatsby-node.js index e7369142def92..7f134cebffd7c 100644 --- a/packages/gatsby/src/internal-plugins/internal-data-bridge/gatsby-node.js +++ b/packages/gatsby/src/internal-plugins/internal-data-bridge/gatsby-node.js @@ -53,7 +53,7 @@ exports.sourceNodes = ({ createContentDigest, actions, store }) => { createNode({ ...page, id: createPageId(page.path), - parent: `SOURCE`, + parent: null, children: [], internal: { type: `SitePage`, @@ -68,7 +68,7 @@ exports.sourceNodes = ({ createContentDigest, actions, store }) => { packageJson: transformPackageJson( require(`${plugin.resolve}/package.json`) ), - parent: `SOURCE`, + parent: null, children: [], internal: { contentDigest: createContentDigest(plugin), @@ -98,7 +98,7 @@ exports.sourceNodes = ({ createContentDigest, actions, store }) => { createNode({ ...node, id: `Site`, - parent: `SOURCE`, + parent: null, children: [], internal: { contentDigest: createContentDigest(node), @@ -138,7 +138,7 @@ exports.onCreatePage = ({ createContentDigest, page, actions }) => { createNode({ ...pageWithoutUpdated, id: createPageId(page.path), - parent: `SOURCE`, + parent: null, children: [], internal: { type: `SitePage`,