Skip to content

Commit

Permalink
chore: use null not "SOURCE" as parent of top level nodes (#10920)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprobst authored and pieh committed Jan 8, 2019
1 parent fdcbe65 commit ac2a54a
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion docs/docs/node-creation.md
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-source-filesystem/src/create-file-node.js
Expand Up @@ -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,
Expand Down
Expand Up @@ -58,7 +58,7 @@ false,\\"nope\\"",
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -87,7 +87,7 @@ false,\\"nope\\"",
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -165,7 +165,7 @@ false,nope",
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -194,7 +194,7 @@ false,nope",
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -223,7 +223,7 @@ false,nope",
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down
Expand Up @@ -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: {
Expand Down
Expand Up @@ -70,7 +70,7 @@ FALSE,nope
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -100,7 +100,7 @@ FALSE,nope
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -128,7 +128,7 @@ FALSE,nope
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -205,7 +205,7 @@ FALSE,nada
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -235,7 +235,7 @@ FALSE,nada
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -263,7 +263,7 @@ FALSE,nada
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -340,7 +340,7 @@ FALSE,nada
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -370,7 +370,7 @@ FALSE,nada
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -398,7 +398,7 @@ FALSE,nada
"mediaType": "text/csv",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down
Expand Up @@ -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: {
Expand Down
Expand Up @@ -48,7 +48,7 @@ Array [
"name": "test",
},
"name": "nodeName",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -121,7 +121,7 @@ Array [
"name": "test",
},
"name": "nodeName",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -158,7 +158,7 @@ Array [
"name": "test",
},
"name": "nodeName",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down
Expand Up @@ -7,7 +7,7 @@ describe(`Process HJSON nodes correctly`, () => {
const node = {
name: `nodeName`,
id: `whatever`,
parent: `SOURCE`,
parent: null,
children: [],
internal: {
contentDigest: `whatever`,
Expand Down
Expand Up @@ -44,7 +44,7 @@ Array [
"type": "File",
},
"name": "nodeName",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -93,7 +93,7 @@ Array [
"mediaType": "application/json",
"type": "NotFile",
},
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -157,7 +157,7 @@ Array [
"type": "File",
},
"name": "nodeName",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -185,7 +185,7 @@ Array [
"type": "File",
},
"name": "nodeName",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -247,7 +247,7 @@ Array [
"mediaType": "application/json",
"type": "NotFile",
},
"parent": "SOURCE",
"parent": null,
},
},
],
Expand All @@ -273,7 +273,7 @@ Array [
"mediaType": "application/json",
"type": "NotFile",
},
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down
Expand Up @@ -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`,
Expand Down
Expand Up @@ -97,7 +97,7 @@ Array [
"contentDigest": "whatever",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down
Expand Up @@ -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: {
Expand Down
Expand Up @@ -206,7 +206,7 @@ Array [
"name": "test",
},
"name": "nodeName",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -299,7 +299,7 @@ Array [
"name": "test",
},
"name": "nodeName",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down
Expand Up @@ -5,7 +5,7 @@ describe(`Process XML nodes correctly`, () => {
const node = {
name: `nodeName`,
id: `whatever`,
parent: `SOURCE`,
parent: null,
children: [],
internal: {
contentDigest: `whatever`,
Expand Down
Expand Up @@ -45,7 +45,7 @@ funny: yup
"mediaType": "text/yaml",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -111,7 +111,7 @@ Array [
"mediaType": "text/yaml",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down Expand Up @@ -141,7 +141,7 @@ Array [
"mediaType": "text/yaml",
},
"name": "test",
"parent": "SOURCE",
"parent": null,
},
},
],
Expand Down
Expand Up @@ -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`,
Expand Down
Expand Up @@ -53,7 +53,7 @@ exports.sourceNodes = ({ createContentDigest, actions, store }) => {
createNode({
...page,
id: createPageId(page.path),
parent: `SOURCE`,
parent: null,
children: [],
internal: {
type: `SitePage`,
Expand All @@ -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),
Expand Down Expand Up @@ -98,7 +98,7 @@ exports.sourceNodes = ({ createContentDigest, actions, store }) => {
createNode({
...node,
id: `Site`,
parent: `SOURCE`,
parent: null,
children: [],
internal: {
contentDigest: createContentDigest(node),
Expand Down Expand Up @@ -138,7 +138,7 @@ exports.onCreatePage = ({ createContentDigest, page, actions }) => {
createNode({
...pageWithoutUpdated,
id: createPageId(page.path),
parent: `SOURCE`,
parent: null,
children: [],
internal: {
type: `SitePage`,
Expand Down

0 comments on commit ac2a54a

Please sign in to comment.