diff --git a/demo/gatsby-config.js b/demo/gatsby-config.js index 3b440d3..e282d0f 100644 --- a/demo/gatsby-config.js +++ b/demo/gatsby-config.js @@ -15,6 +15,7 @@ module.exports = { 'https://api-eu-central-1.graphcms.com/v2/ckclvjtet0f0901z69og3f3gm/master', locales: ['en', 'de'], stages: ['DRAFT', 'PUBLISHED'], + richTextEmbedTypeNames: ['ProductDescription'], }, }, ], diff --git a/demo/graphcms-fragments/Asset.graphql b/demo/graphcms-fragments/Asset.graphql index 4869e3a..ca4a659 100644 --- a/demo/graphcms-fragments/Asset.graphql +++ b/demo/graphcms-fragments/Asset.graphql @@ -11,11 +11,40 @@ fragment Asset on Asset { width size mimeType + createdBy { + ... on User { + remoteTypeName: __typename + remoteId: id + stage + } + } + updatedBy { + ... on User { + remoteTypeName: __typename + remoteId: id + stage + } + } + publishedBy { + ... on User { + remoteTypeName: __typename + remoteId: id + stage + } + } productImages { ... on Product { remoteTypeName: __typename remoteId: id locale + stage + } + } + scheduledIn { + ... on ScheduledOperation { + remoteTypeName: __typename + remoteId: id + stage } } url diff --git a/demo/graphcms-fragments/Category.graphql b/demo/graphcms-fragments/Category.graphql index 51500c9..74cba6d 100644 --- a/demo/graphcms-fragments/Category.graphql +++ b/demo/graphcms-fragments/Category.graphql @@ -6,11 +6,40 @@ fragment Category on Category { updatedAt(variation: COMBINED) publishedAt(variation: COMBINED) name + createdBy { + ... on User { + remoteTypeName: __typename + remoteId: id + stage + } + } + updatedBy { + ... on User { + remoteTypeName: __typename + remoteId: id + stage + } + } + publishedBy { + ... on User { + remoteTypeName: __typename + remoteId: id + stage + } + } products { ... on Product { remoteTypeName: __typename remoteId: id locale + stage + } + } + scheduledIn { + ... on ScheduledOperation { + remoteTypeName: __typename + remoteId: id + stage } } } \ No newline at end of file diff --git a/demo/graphcms-fragments/Product.graphql b/demo/graphcms-fragments/Product.graphql index 8c25d8c..65d0409 100644 --- a/demo/graphcms-fragments/Product.graphql +++ b/demo/graphcms-fragments/Product.graphql @@ -8,19 +8,70 @@ fragment Product on Product { name slug description { - ... on RichText { + ... on ProductDescriptionRichText { raw + json html markdown text + references { + ... on Asset { + remoteTypeName: __typename + remoteId: id + locale + stage + } + ... on Category { + remoteTypeName: __typename + remoteId: id + locale + stage + } + ... on Product { + remoteTypeName: __typename + remoteId: id + locale + stage + } + } } } price + test { + ... on RichText { + raw + html + markdown + text + } + } + createdBy { + ... on User { + remoteTypeName: __typename + remoteId: id + stage + } + } + updatedBy { + ... on User { + remoteTypeName: __typename + remoteId: id + stage + } + } + publishedBy { + ... on User { + remoteTypeName: __typename + remoteId: id + stage + } + } images { ... on Asset { remoteTypeName: __typename remoteId: id locale + stage } } categories { @@ -28,6 +79,14 @@ fragment Product on Product { remoteTypeName: __typename remoteId: id locale + stage + } + } + scheduledIn { + ... on ScheduledOperation { + remoteTypeName: __typename + remoteId: id + stage } } } \ No newline at end of file diff --git a/demo/graphcms-fragments/User.graphql b/demo/graphcms-fragments/User.graphql index 654c58b..5cdc585 100644 --- a/demo/graphcms-fragments/User.graphql +++ b/demo/graphcms-fragments/User.graphql @@ -6,6 +6,6 @@ fragment User on User { publishedAt name picture - kind isActive + kind } \ No newline at end of file diff --git a/gatsby-source-graphcms/src/gatsby-node.js b/gatsby-source-graphcms/src/gatsby-node.js index 9f149d9..be8383b 100644 --- a/gatsby-source-graphcms/src/gatsby-node.js +++ b/gatsby-source-graphcms/src/gatsby-node.js @@ -74,6 +74,10 @@ export function pluginOptionsSchema({ Joi }) { .min(1) .default(10) .description(`The number of promises to run at one time.`), + richTextEmbedTypeNames: Joi.array() + .description('An array of Rich Text fields that have embeds enabled') + .items(Joi.string()) + .default([]), }) } @@ -219,6 +223,7 @@ export async function createSchemaCustomization(gatsbyApi, pluginOptions) { buildMarkdownNodes = false, downloadLocalImages = false, typePrefix = 'GraphCMS_', + richTextEmbedTypeNames = [], } = pluginOptions const config = await createSourcingConfig(gatsbyApi, pluginOptions) @@ -274,6 +279,13 @@ export async function createSchemaCustomization(gatsbyApi, pluginOptions) { type ${typePrefix}RichText { markdownNode: ${typePrefix}MarkdownNode @link } + ${richTextEmbedTypeNames.map( + (typeName) => ` + type ${typePrefix}${typeName}RichText implements Node { + markdownNode: ${typePrefix}MarkdownNode @link + } + ` + )} `) } @@ -312,7 +324,9 @@ export async function onCreateNode( .map(([key, value]) => ({ key, value })) .filter( ({ value }) => - value && value.remoteTypeName && value.remoteTypeName === 'RichText' + value && + value.remoteTypeName && + value.remoteTypeName.endsWith('RichText') ) if (fields.length) {