-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(gatsby-source-contentful): add support for setting type prefix #37981
Conversation
packages/gatsby-source-contentful/src/__tests__/__snapshots__/gatsby-node.js.snap
Outdated
Show resolved
Hide resolved
name: `ContentfulAsset`, | ||
}) | ||
) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking both that it created the types with the prefix, but also that it doesn't create types with the default
currentSyncData?.entries.length + | ||
currentSyncData?.assets.length + | ||
currentSyncData?.deletedEntries.length + | ||
currentSyncData?.deletedAssets.length === | ||
0 | ||
!currentSyncData?.entries.length && | ||
!currentSyncData?.assets.length && | ||
!currentSyncData?.deletedEntries.length && | ||
!currentSyncData?.deletedAssets.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thsi was giving TS errors, because it was trying to perform arithmetic when the value is possibly null (thanks to the optional chain)
const typePrefix = `Contentful` | ||
export const makeTypeName = type => | ||
/** | ||
* @param {string} type | ||
* @param {string} typePrefix | ||
*/ | ||
export const makeTypeName = (type, typePrefix) => | ||
_.upperFirst(_.camelCase(`${typePrefix} ${type}`)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typePrefix
was already a thing, it was just previously hard-coded
_.upperFirst(_.camelCase(`${typePrefix} ${type}`)) | ||
export const assetTypeName = makeTypeName(`Asset`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't hard-code this anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Another feature of the rewrite finding itself in the old version :D Good job! |
Description
Adds support for
typePrefix
togatsby-source-contentful
. This is prefixed to the names of the generated node types. It defaults toContentful
, which is the current value used.Documentation
Added to readme
Tests
Added unit tests.
Related Issues
Fixes https://github.com/gatsby-inc/netlify-valhalla/issues/178