-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Should node id's be unique and meaningless? #23638
Comments
#22004 is example of issues when The "meaningless" part is somewhat related to uniqueness - it's not strict requirement, but it is good practice - when users would want to query by
It does sound like the documentation adjustments is good idea, but there is always nuance. Sometimes we don't want to go on tangential problem when explaining some particular concept. So we might need to evaluate this for each documentation page separately - do you have examples in mind? |
Thanks for clarifying. I'll def use the second option and store I see what you mean about the nuance. Don't want to overwhelm someone! I was thinking mostly about the Node creation page and specifically the Node relationship storage model section. It explains the flat dictionary you referenced above and the implications, and does make a reference to child field inference. I wonder if this is a good place to explain about unique/meaningless ids? Or possibly a new section alongside Parent/Child/Refs, Fresh/stale nodes, Changing a node's fields and Node Tracking - it definitely fits on that page as one of the fairly important things to know. |
Hey @ediblecode, thanks for opening the issue! And thanks to @pieh for the initial triage. I think a new section on the Node Creation page about handling IDs would be awesome. If you're up for contributing it, I'd say go for it! |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Not stale, still going to submit a PR for the updated docs just haven't got round to it, sorry |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Thanks again for being part of the Gatsby community! 💪💜 |
Summary
I'm writing a source plugin where I download JSON from an API and create nodes - all pretty standard. Objects I receive have an a field called
topicId
with is a guid (uuid) that represents the main id of the item.Now I could use this field directly as the node id in Gatsby like this:
However, the
createNodeId
function exists (to create guid ids) so it seems like I should use it, and store thetopicid
as its own field, like this:So the question is, should id's be unique and meaningless? And therefore which approach above is favourable?
One of the benefits of
createNodeId
is that it 'will generate different IDs for different plugins if they use same input'. In my particular case, this is irrelevant because I've already got a guid, so I could probably safely just use it directly.Relevant information
This comment suggests that node ids should be unique and meaningless, so people don't rely on them for anything, which makes sense.
However, I couldn't find anything about this in the docs either in node creation or createNodeId. In fact, several of the examples in the docs actually don't use
createNodeId
and use predictable ids directly.I'd be happy to contribute to the docs if anyone thinks this needs adding/clarifying.
Environment (if relevant)
N/A
File contents (if changed)
gatsby-config.js
: N/Apackage.json
: N/Agatsby-node.js
: N/Agatsby-browser.js
: N/Agatsby-ssr.js
: N/AThe text was updated successfully, but these errors were encountered: