Skip to content

Commit

Permalink
shorten union names
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed May 20, 2021
1 parent 629640a commit 5f18b1d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
14 changes: 9 additions & 5 deletions packages/gatsby-source-contentful/src/generate-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,19 @@ const getLinkFieldType = (linkType, field, schema, createTypes) => {
// { validations: [ { linkContentType: [Array] } ] }
if (linkContentTypeValidation) {
const { linkContentType } = linkContentTypeValidation
const translatedTypeNames = linkContentType.map(makeTypeName)

// Full type names for union members, shorter variant for the union type name
const translatedTypeNames = linkContentType.map(typeName =>
makeTypeName(typeName)
)
const shortTypeNames = linkContentType.map(typeName =>
makeTypeName(typeName, ``)
)

// @todo Single content type

// Multiple content types
const unionName = [
`UnionContentfulContentTypes`,
...translatedTypeNames,
].join(``)
const unionName = [`UnionContentful`, ...shortTypeNames].join(``)

if (!unionsNameSet.has(unionName)) {
unionsNameSet.add(unionName)
Expand Down
3 changes: 1 addition & 2 deletions packages/gatsby-source-contentful/src/normalize.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const _ = require(`lodash`)

const typePrefix = `Contentful`
export const makeTypeName = type =>
export const makeTypeName = (type, typePrefix = `Contentful`) =>
_.upperFirst(_.camelCase(`${typePrefix} ${type}`))

const getLocalizedField = ({ field, locale, localesFallback }) => {
Expand Down

0 comments on commit 5f18b1d

Please sign in to comment.