Skip to content

Commit

Permalink
fix: namespace globally unique nodes with typePrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Feb 22, 2021
1 parent 8327cb3 commit 159d4de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/index.ts
Expand Up @@ -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`
*/
Expand Down Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.ts
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 159d4de

Please sign in to comment.