Skip to content

Commit

Permalink
fix: custom content type prefix option now actually affects the gener…
Browse files Browse the repository at this point in the history
…ated content type names and not only the schema
  • Loading branch information
axe312ger committed Oct 13, 2023
1 parent 8cfe253 commit c0a0ba5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
20 changes: 18 additions & 2 deletions packages/gatsby-source-contentful/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,13 +674,29 @@ describe(`gatsby-node`, () => {

expect(schema.buildObjectType).not.toHaveBeenCalledWith(
expect.objectContaining({
name: `ContentfulPerson`,
name: `ContentfulContentTypePerson`,
})
)

expect(schema.buildObjectType).not.toHaveBeenCalledWith(
expect.objectContaining({
name: `ContentfulBlogPost`,
name: `ContentfulContentTypeBlogPost`,
})
)

expect(actions.createNode).not.toHaveBeenCalledWith(
expect.objectContaining({
internal: expect.objectContaining({
type: `ContentfulContentTypeBlogPost`,
}),
})
)

expect(actions.createNode).not.toHaveBeenCalledWith(
expect.objectContaining({
internal: expect.objectContaining({
type: `ContentfulContentTypePerson`,
}),
})
)
})
Expand Down
3 changes: 2 additions & 1 deletion packages/gatsby-source-contentful/src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ export const createNodesForContentType = ({
const markdownFields: MarkdownFieldDefinition = new Map(
pluginConfig.get(`markdownFields`)
)
const contentTypePrefix: string = pluginConfig.get(`contentTypePrefix`)

// Establish identifier for content type
// Use `name` if specified, otherwise, use internal id (usually a natural-language constant,
Expand Down Expand Up @@ -784,7 +785,7 @@ export const createNodesForContentType = ({
parent: contentTypeItemId,
children: [],
internal: {
type: makeTypeName(contentTypeItemId),
type: makeTypeName(contentTypeItemId, contentTypePrefix),
// The content of an entry is guaranteed to be updated if and only if the .sys.updatedAt field changed
contentDigest: entryItem.sys.updatedAt,
},
Expand Down

0 comments on commit c0a0ba5

Please sign in to comment.