queen.raae.codes · a developer’s logbook
1 min read

How to create unique Gatsby node ids

Written in 2022, 4 years ago. Tools and advice may have moved on since.

All Gatsby nodes need a unique id. Luckily for you, a Gatsby Source Plugin developer, you are not responsible for creating unique ids. You are only responsible for supplying a unique-within-your-universe-id to createNodeId. Gatsby is responsible for returning a unique node id.

exports.sourceNodes = async ({ actions, createNodeId }) => {
  const { createNode } = actions;

  createNode({
    id: createNodeId("unique-within-your-universe-id"),

    // More fields
  });
};

In Gatsby Source YouTube oEmbed we use the YouTube id. It is unique across the YouTube universe.

 
All the best,
Queen Raae

 
PS: createNodeId is deterministic

Join the crew!

All the shenanigans from me and my piratical family, straight to your inbox.

Search the log

↑↓ to move · Enter to open · Esc to close All entries →