From 159d4dec7541693de956e6a0e9153a58f766c044 Mon Sep 17 00:00:00 2001 From: Angelo Ashmore Date: Sun, 21 Feb 2021 16:27:05 -1000 Subject: [PATCH] fix: namespace globally unique nodes with typePrefix --- src/index.ts | 13 +++++++------ test/index.test.ts | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index 70e6c87..dd444ca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -144,13 +144,14 @@ export interface NodeHelpers { */ type CreateNodeFactoryOptions = { /** - * Determines if the node's `id` field is globally unique. Globally in this - * context means across all nodes in your application or package. + * Determines if the node's `id` field is unique within all nodes created with + * this collection of node helpers. * - * If `true`, the ID will be passed directly to Gatsby's `createNodeId` - * function. + * If `false`, the ID will be namespaced with the node's type and the + * `typePrefix` value. * - * If `false`, the ID will be namespaced with the node's type. + * If `true`, the ID will not be namespaced with the node's type, but will still + * be namespaced with the `typePrefix` value. * * @defaultValue `false` */ @@ -182,7 +183,7 @@ export const createNodeHelpers = ({ { idIsGloballyUnique = false }: CreateNodeFactoryOptions = {}, ) => (node: IdentifiableRecord): gatsby.NodeInput => { const id = idIsGloballyUnique - ? gatsbyCreateNodeId(node.id.toString()) + ? createNodeId(node.id.toString()) : createNodeId([...castArray(nameParts), node.id.toString()]) const res = { diff --git a/test/index.test.ts b/test/index.test.ts index 1f304ef..ac24963 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -139,7 +139,7 @@ describe('createNodeFactory', () => { }) const modifiedNodeInput = modifiedFn(node) - expect(modifiedNodeInput.id).toBe(`createNodeId(${node.id})`) + expect(modifiedNodeInput.id).toBe(`createNodeId(typePrefix ${node.id})`) }) test('adds internal field with required Gatsby fields', () => {