diff --git a/e2e-tests/contentful/src/pages/content-reference.js b/e2e-tests/contentful/src/pages/content-reference.js index cda2d6bea69a7..af22aaf056014 100644 --- a/e2e-tests/contentful/src/pages/content-reference.js +++ b/e2e-tests/contentful/src/pages/content-reference.js @@ -115,6 +115,11 @@ export const pageQuery = graphql` } ... on ContentfulContentReference { title + ... on ContentfulEntry { + sys { + id + } + } one { ... on ContentfulText { title diff --git a/packages/gatsby-source-contentful/src/generate-schema.js b/packages/gatsby-source-contentful/src/generate-schema.js index 556efc3f5c446..541ad2429f67e 100644 --- a/packages/gatsby-source-contentful/src/generate-schema.js +++ b/packages/gatsby-source-contentful/src/generate-schema.js @@ -84,16 +84,27 @@ const getLinkFieldType = (linkType, field, schema, createTypes) => { // { validations: [ { linkContentType: [Array] } ] } if (linkContentTypeValidation) { const { linkContentType } = linkContentTypeValidation + const contentTypes = Array.isArray(linkContentType) + ? linkContentType + : [linkContentType] // Full type names for union members, shorter variant for the union type name - const translatedTypeNames = linkContentType.map(typeName => + const translatedTypeNames = contentTypes.map(typeName => makeTypeName(typeName) ) - const shortTypeNames = linkContentType.map(typeName => + const shortTypeNames = contentTypes.map(typeName => makeTypeName(typeName, ``) ) - // @todo Single content type + // Single content type + if (translatedTypeNames.length === 1) { + return { + type: translatedTypeNames.shift(), + extensions: { + link: { by: `id`, from: `${field.id}___NODE` }, + }, + } + } // Multiple content types const unionName = [`UnionContentful`, ...shortTypeNames].join(``)