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

V2 - Switch Sources and Transformers to use createNodeId for ids #3807

Merged
merged 4 commits into from
Feb 10, 2018

Conversation

danielfarrell
Copy link
Contributor

Fixes #1853

@ghost ghost assigned danielfarrell Feb 1, 2018
@ghost ghost added the review label Feb 1, 2018
@danielfarrell danielfarrell changed the title Switch Sources and Transformers to use createNodeId for ids V2 - Switch Sources and Transformers to use createNodeId for ids Feb 1, 2018
@@ -28,8 +28,5 @@
"main": "index.js",
"readme": "README.md",
"scripts": {
"build": "babel src --out-dir . --ignore __tests__",
"watch": "babel -w src --out-dir . --ignore __tests__",
"prepublish": "cross-env NODE_ENV=production npm run build"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this whole package should be deleted, the files here are leftover from a bad merge with master

Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

@@ -36,7 +36,7 @@ async function onCreateNode({ node, actions, loadNodeContent }, options) {

return {
...obj,
id: obj.id ? obj.id : `${node.id} [${i}] >>> CSV`,
id: createNodeId(obj.id ? obj.id : `${node.id} [${i}] >>> CSV`),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should let people explicitly set IDs. There are use cases for that e.g. when creating mappings between nodes like we do for blog authors on gatsbyjs.org

mapping: {

In nodes created from potentially manually created data, we should leave IDs alone.

@@ -36,7 +36,7 @@ async function onCreateNode({ node, actions, loadNodeContent }, options) {

return {
...obj,
id: obj.id ? obj.id : `${node.id} [${n} ${i}] >>> ${node.extension}`,
id: createNodeId(obj.id ? obj.id : `${node.id} [${n} ${i}] >>> ${node.extension}`),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, don't hash the manually created ID

@@ -12,7 +14,7 @@ async function onCreateNode({ node, actions, loadNodeContent }) {
.digest(`hex`)
const jsonNode = {
...obj,
id,
id: createNodeId(id),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we never were creating an ID if it was missing. Could you add that? But same here as the others, don't hash the manually created ID

@@ -11,7 +11,7 @@ async function onCreateNode({ node, actions, loadNodeContent }) {
.digest(`hex`)
const jsonNode = {
...obj,
id,
id: createNodeId(id),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, don't hash the manually created ID

@@ -26,7 +26,7 @@ async function onCreateNode({ node, actions, loadNodeContent }) {

const newNode = {
...parsedContent,
id: parsedContent.id ? parsedContent.id : `${node.id} >>> TOML`,
id: createNodeId(parsedContent.id ? parsedContent.id : `${node.id} >>> TOML`),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, don't hash the manually created ID

@danielfarrell
Copy link
Contributor Author

I must be confused about the goal here. I thought we specifically wanted to push everything to get uuids for their ids. Using UUIDv5 only makes sense when you supply an id to it. It will be stable if you provide something stable, but still namespaced to the plugin.

@pieh
Copy link
Contributor

pieh commented Feb 6, 2018

@danielfarrell I suspect reason to allow using supplied ids in json (and similar) transformers is that they are often used to link/join nodes with mapping.

For example gatsby website use this to link blog post authors to author nodes. Below links how it is set up:

UUIDv5ing it would break mapping feature usage in current form - we would at very least need to figure out alternative convention to do this (so not try to link on node id, but on different field - maybe add another reserved field with original/source id and try to use that to link or allow specyfing in mapping settings which field to join on)

@KyleAMathews
Copy link
Contributor

Yeah, if a user manually adds an ID then it's reasonable that they'd want to be able to link to elsewhere. UUIDs are mostly for improving how source/transformers auto-generate IDs. Instead of leaving them 1/2 meaningful e.g. /path/to/file >>> transformer-json we generate a truly meaningless ID w/ the UUID lib. We don't want people to be relying on IDs meaning something unless they create those themselves.

@KyleAMathews
Copy link
Contributor

@danielfarrell I'll take this over — hope your health issues work out!

@ghost ghost assigned KyleAMathews Feb 10, 2018
@KyleAMathews KyleAMathews merged commit 613c56b into gatsbyjs:v2 Feb 10, 2018
@ghost ghost removed the review label Feb 10, 2018
@KyleAMathews
Copy link
Contributor

Thanks @danielfarrell for your great work!

This was referenced Sep 5, 2021
mwfrost pushed a commit to mwfrost/gatsby that referenced this pull request Apr 20, 2023
…sbyjs#3807)

* Switch Sources and Transformers to use createNodeId for ids

* Only use createNodeId if an id isn't passed in

* Remove unused imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants