Skip to content

Commit

Permalink
fix: temp explicit rich text typenames
Browse files Browse the repository at this point in the history
  • Loading branch information
notrab committed Jan 10, 2022
1 parent efcc239 commit 665a5db
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 3 deletions.
1 change: 1 addition & 0 deletions demo/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
'https://api-eu-central-1.graphcms.com/v2/ckclvjtet0f0901z69og3f3gm/master',
locales: ['en', 'de'],
stages: ['DRAFT', 'PUBLISHED'],
richTextEmbedTypeNames: ['ProductDescription'],
},
},
],
Expand Down
29 changes: 29 additions & 0 deletions demo/graphcms-fragments/Asset.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions demo/graphcms-fragments/Category.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
61 changes: 60 additions & 1 deletion demo/graphcms-fragments/Product.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,85 @@ 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 {
... on Category {
remoteTypeName: __typename
remoteId: id
locale
stage
}
}
scheduledIn {
... on ScheduledOperation {
remoteTypeName: __typename
remoteId: id
stage
}
}
}
2 changes: 1 addition & 1 deletion demo/graphcms-fragments/User.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ fragment User on User {
publishedAt
name
picture
kind
isActive
kind
}
16 changes: 15 additions & 1 deletion gatsby-source-graphcms/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([]),
})
}

Expand Down Expand Up @@ -219,6 +223,7 @@ export async function createSchemaCustomization(gatsbyApi, pluginOptions) {
buildMarkdownNodes = false,
downloadLocalImages = false,
typePrefix = 'GraphCMS_',
richTextEmbedTypeNames = [],
} = pluginOptions

const config = await createSourcingConfig(gatsbyApi, pluginOptions)
Expand Down Expand Up @@ -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
}
`
)}
`)
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 665a5db

Please sign in to comment.