Skip to content

Commit 665a5db

Browse files
committed
fix: temp explicit rich text typenames
1 parent efcc239 commit 665a5db

File tree

6 files changed

+135
-3
lines changed

6 files changed

+135
-3
lines changed

demo/gatsby-config.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
'https://api-eu-central-1.graphcms.com/v2/ckclvjtet0f0901z69og3f3gm/master',
1616
locales: ['en', 'de'],
1717
stages: ['DRAFT', 'PUBLISHED'],
18+
richTextEmbedTypeNames: ['ProductDescription'],
1819
},
1920
},
2021
],

demo/graphcms-fragments/Asset.graphql

+29
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,40 @@ fragment Asset on Asset {
1111
width
1212
size
1313
mimeType
14+
createdBy {
15+
... on User {
16+
remoteTypeName: __typename
17+
remoteId: id
18+
stage
19+
}
20+
}
21+
updatedBy {
22+
... on User {
23+
remoteTypeName: __typename
24+
remoteId: id
25+
stage
26+
}
27+
}
28+
publishedBy {
29+
... on User {
30+
remoteTypeName: __typename
31+
remoteId: id
32+
stage
33+
}
34+
}
1435
productImages {
1536
... on Product {
1637
remoteTypeName: __typename
1738
remoteId: id
1839
locale
40+
stage
41+
}
42+
}
43+
scheduledIn {
44+
... on ScheduledOperation {
45+
remoteTypeName: __typename
46+
remoteId: id
47+
stage
1948
}
2049
}
2150
url

demo/graphcms-fragments/Category.graphql

+29
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,40 @@ fragment Category on Category {
66
updatedAt(variation: COMBINED)
77
publishedAt(variation: COMBINED)
88
name
9+
createdBy {
10+
... on User {
11+
remoteTypeName: __typename
12+
remoteId: id
13+
stage
14+
}
15+
}
16+
updatedBy {
17+
... on User {
18+
remoteTypeName: __typename
19+
remoteId: id
20+
stage
21+
}
22+
}
23+
publishedBy {
24+
... on User {
25+
remoteTypeName: __typename
26+
remoteId: id
27+
stage
28+
}
29+
}
930
products {
1031
... on Product {
1132
remoteTypeName: __typename
1233
remoteId: id
1334
locale
35+
stage
36+
}
37+
}
38+
scheduledIn {
39+
... on ScheduledOperation {
40+
remoteTypeName: __typename
41+
remoteId: id
42+
stage
1443
}
1544
}
1645
}

demo/graphcms-fragments/Product.graphql

+60-1
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,85 @@ fragment Product on Product {
88
name
99
slug
1010
description {
11-
... on RichText {
11+
... on ProductDescriptionRichText {
1212
raw
13+
json
1314
html
1415
markdown
1516
text
17+
references {
18+
... on Asset {
19+
remoteTypeName: __typename
20+
remoteId: id
21+
locale
22+
stage
23+
}
24+
... on Category {
25+
remoteTypeName: __typename
26+
remoteId: id
27+
locale
28+
stage
29+
}
30+
... on Product {
31+
remoteTypeName: __typename
32+
remoteId: id
33+
locale
34+
stage
35+
}
36+
}
1637
}
1738
}
1839
price
40+
test {
41+
... on RichText {
42+
raw
43+
html
44+
markdown
45+
text
46+
}
47+
}
48+
createdBy {
49+
... on User {
50+
remoteTypeName: __typename
51+
remoteId: id
52+
stage
53+
}
54+
}
55+
updatedBy {
56+
... on User {
57+
remoteTypeName: __typename
58+
remoteId: id
59+
stage
60+
}
61+
}
62+
publishedBy {
63+
... on User {
64+
remoteTypeName: __typename
65+
remoteId: id
66+
stage
67+
}
68+
}
1969
images {
2070
... on Asset {
2171
remoteTypeName: __typename
2272
remoteId: id
2373
locale
74+
stage
2475
}
2576
}
2677
categories {
2778
... on Category {
2879
remoteTypeName: __typename
2980
remoteId: id
3081
locale
82+
stage
83+
}
84+
}
85+
scheduledIn {
86+
... on ScheduledOperation {
87+
remoteTypeName: __typename
88+
remoteId: id
89+
stage
3190
}
3291
}
3392
}

demo/graphcms-fragments/User.graphql

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ fragment User on User {
66
publishedAt
77
name
88
picture
9-
kind
109
isActive
10+
kind
1111
}

gatsby-source-graphcms/src/gatsby-node.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export function pluginOptionsSchema({ Joi }) {
7474
.min(1)
7575
.default(10)
7676
.description(`The number of promises to run at one time.`),
77+
richTextEmbedTypeNames: Joi.array()
78+
.description('An array of Rich Text fields that have embeds enabled')
79+
.items(Joi.string())
80+
.default([]),
7781
})
7882
}
7983

@@ -219,6 +223,7 @@ export async function createSchemaCustomization(gatsbyApi, pluginOptions) {
219223
buildMarkdownNodes = false,
220224
downloadLocalImages = false,
221225
typePrefix = 'GraphCMS_',
226+
richTextEmbedTypeNames = [],
222227
} = pluginOptions
223228

224229
const config = await createSourcingConfig(gatsbyApi, pluginOptions)
@@ -274,6 +279,13 @@ export async function createSchemaCustomization(gatsbyApi, pluginOptions) {
274279
type ${typePrefix}RichText {
275280
markdownNode: ${typePrefix}MarkdownNode @link
276281
}
282+
${richTextEmbedTypeNames.map(
283+
(typeName) => `
284+
type ${typePrefix}${typeName}RichText implements Node {
285+
markdownNode: ${typePrefix}MarkdownNode @link
286+
}
287+
`
288+
)}
277289
`)
278290
}
279291

@@ -312,7 +324,9 @@ export async function onCreateNode(
312324
.map(([key, value]) => ({ key, value }))
313325
.filter(
314326
({ value }) =>
315-
value && value.remoteTypeName && value.remoteTypeName === 'RichText'
327+
value &&
328+
value.remoteTypeName &&
329+
value.remoteTypeName.endsWith('RichText')
316330
)
317331

318332
if (fields.length) {

0 commit comments

Comments
 (0)