Skip to content
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

Merged
merged 8 commits into from
May 1, 2023

Conversation

ascorbic
Copy link
Contributor

Description

Adds support for typePrefix to gatsby-source-contentful. This is prefixed to the names of the generated node types. It defaults to Contentful, 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

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Apr 27, 2023
name: `ContentfulAsset`,
})
)
})
Copy link
Contributor Author

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

Comment on lines -336 to +339
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
Copy link
Contributor Author

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)

Comment on lines -8 to 13
const typePrefix = `Contentful`
export const makeTypeName = type =>
/**
* @param {string} type
* @param {string} typePrefix
*/
export const makeTypeName = (type, typePrefix) =>
_.upperFirst(_.camelCase(`${typePrefix} ${type}`))
Copy link
Contributor Author

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`)
Copy link
Contributor Author

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

@LekoArts LekoArts added topic: source-contentful Related to Gatsby's integration with Contentful topic: source-plugins Relates to the Gatsby source plugins (e.g. -filesystem) and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Apr 27, 2023
DanielSLew
DanielSLew previously approved these changes Apr 27, 2023
Copy link
Contributor

@DanielSLew DanielSLew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@DanielSLew DanielSLew merged commit 8c9b0d4 into gatsbyjs:master May 1, 2023
@axe312ger
Copy link
Collaborator

Another feature of the rewrite finding itself in the old version :D

Good job!

@ascorbic ascorbic deleted the contentful-prefix branch May 2, 2023 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: source-contentful Related to Gatsby's integration with Contentful topic: source-plugins Relates to the Gatsby source plugins (e.g. -filesystem)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants