Skip to content

Commit 925a655

Browse files
sarahannnicholsonpieh
authored andcommitted
feat(gatsby-source-wordpress): use unique multi-site node id's (#12683)
## Description There was a little bug where in a multi-site config of the gatsby-source-wordpress plugin, the id's of the graphQL nodes were not always unique. Since the node id's were mainly being generated by the node.__type, in the case of two post types had the same type and id (even though they were from different data sources), resulted in only 1 graphQL node being created. This PR adds the __siteUrl to the id generation to resolve this issue. (My previous PR needed to pull upstream changes, hopefully all circleci tests will pass) ## Related Issues The changes in this PR will resolve this issue where [multi-site WordPress config looses data](#12608)
1 parent 9c74ad8 commit 925a655

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

packages/gatsby-source-wordpress/src/__tests__/normalize.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ describe(`Process WordPress data`, () => {
2525
it(`creates Gatsby IDs for each entity`, () => {
2626
const createNodeId = jest.fn()
2727
createNodeId.mockReturnValue(`uuid-from-gatsby`)
28-
entities = normalize.createGatsbyIds(createNodeId, entities)
28+
entities = normalize.createGatsbyIds(
29+
createNodeId,
30+
entities,
31+
`http://dev-gatbsyjswp.pantheonsite.io`
32+
)
2933
expect(entities).toMatchSnapshot()
3034
})
3135
it(`Creates map of types`, () => {

packages/gatsby-source-wordpress/src/gatsby-node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ exports.sourceNodes = async (
9696
entities = normalize.excludeUnknownEntities(entities)
9797

9898
// Creates Gatsby IDs for each entity
99-
entities = normalize.createGatsbyIds(createNodeId, entities)
99+
entities = normalize.createGatsbyIds(createNodeId, entities, _siteURL)
100100

101101
// Creates links between authors and user entities
102102
entities = normalize.mapAuthorsToUsers(entities)

packages/gatsby-source-wordpress/src/normalize.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,14 @@ exports.excludeUnknownEntities = entities =>
179179
// Create node ID from known entities
180180
// excludeUnknownEntities whitelisted types don't contain a wordpress_id
181181
// we create the node ID based upon type if the wordpress_id doesn't exist
182-
exports.createGatsbyIds = (createNodeId, entities) =>
182+
exports.createGatsbyIds = (createNodeId, entities, _siteURL) =>
183183
entities.map(e => {
184184
if (e.wordpress_id) {
185-
e.id = createNodeId(`${e.__type}-${e.wordpress_id.toString()}`)
185+
e.id = createNodeId(
186+
`${e.__type}-${e.wordpress_id.toString()}-${_siteURL}`
187+
)
186188
} else {
187-
e.id = createNodeId(e.__type)
189+
e.id = createNodeId(`${e.__type}-${_siteURL}`)
188190
}
189191
return e
190192
})

0 commit comments

Comments
 (0)