Skip to content

Commit a5715aa

Browse files
committed
feat: use union for reference fields with validation (#31395)
Also: * test: add unit tests for schema customization * fix: rich text inline rendering * test: update e2e test schema dump
1 parent 0be1d7b commit a5715aa

File tree

9 files changed

+1820
-56
lines changed

9 files changed

+1820
-56
lines changed

e2e-tests/contentful/schema.gql

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ type Directory implements Node @dontInfer {
7474
type Site implements Node @dontInfer {
7575
buildTime: Date @dateformat
7676
siteMetadata: SiteSiteMetadata
77-
port: Int
78-
host: String
7977
polyfill: Boolean
8078
pathPrefix: String
8179
jsxRuntime: String
@@ -124,12 +122,11 @@ type SiteBuildMetadata implements Node @dontInfer {
124122

125123
interface ContentfulReference implements Node {
126124
id: ID!
127-
sys: ContentfulSys
125+
sys: ContentfulSys!
128126
}
129127

130-
type ContentfulSys {
128+
type ContentfulSys implements Node @dontInfer {
131129
type: String!
132-
id: String!
133130
spaceId: String!
134131
environmentId: String!
135132
contentType: ContentfulContentType @link(by: "id", from: "contentType___NODE")
@@ -145,13 +142,27 @@ type ContentfulContentType implements Node @dontInfer {
145142
description: String!
146143
}
147144

148-
interface ContentfulEntry implements Node {
145+
interface ContentfulEntry implements ContentfulReference & Node {
149146
id: ID!
150-
sys: ContentfulSys
147+
sys: ContentfulSys!
148+
metadata: ContentfulMetadata!
149+
}
150+
151+
type ContentfulMetadata @dontInfer {
152+
tags: [ContentfulTag]! @link(by: "id", from: "tags___NODE")
153+
}
154+
155+
type ContentfulTag implements Node @dontInfer {
156+
name: String!
157+
contentful_id: String!
158+
}
159+
160+
type ContentfulAssetFields @dontInfer {
161+
localFile: File @link(by: "id")
151162
}
152163

153164
type ContentfulAsset implements ContentfulReference & Node @dontInfer {
154-
sys: ContentfulSys
165+
sys: ContentfulSys!
155166
title: String
156167
description: String
157168
contentType: String
@@ -163,15 +174,6 @@ type ContentfulAsset implements ContentfulReference & Node @dontInfer {
163174
fields: ContentfulAssetFields
164175
}
165176

166-
type ContentfulAssetFields {
167-
localFile: String
168-
}
169-
170-
type ContentfulTag implements Node @dontInfer {
171-
name: String!
172-
contentful_id: String!
173-
}
174-
175177
type ContentfulRichTextAssets {
176178
block: [ContentfulAsset]!
177179
hyperlink: [ContentfulAsset]!
@@ -203,7 +205,8 @@ type ContentfulText implements Node @dontInfer {
203205
}
204206

205207
type ContentfulContentTypeNumber implements ContentfulReference & ContentfulEntry & Node @dontInfer {
206-
sys: ContentfulSys
208+
sys: ContentfulSys!
209+
metadata: ContentfulMetadata!
207210
title: String
208211
integer: Int
209212
integerLocalized: Int
@@ -212,7 +215,8 @@ type ContentfulContentTypeNumber implements ContentfulReference & ContentfulEntr
212215
}
213216

214217
type ContentfulContentTypeText implements ContentfulReference & ContentfulEntry & Node @dontInfer {
215-
sys: ContentfulSys
218+
sys: ContentfulSys!
219+
metadata: ContentfulMetadata!
216220
title: String
217221
short: String
218222
shortLocalized: String
@@ -224,7 +228,8 @@ type ContentfulContentTypeText implements ContentfulReference & ContentfulEntry
224228
}
225229

226230
type ContentfulContentTypeMediaReference implements ContentfulReference & ContentfulEntry & Node @dontInfer {
227-
sys: ContentfulSys
231+
sys: ContentfulSys!
232+
metadata: ContentfulMetadata!
228233
title: String
229234
one: ContentfulAsset @link(by: "id", from: "one___NODE")
230235
oneLocalized: ContentfulAsset @link(by: "id", from: "oneLocalized___NODE")
@@ -233,14 +238,16 @@ type ContentfulContentTypeMediaReference implements ContentfulReference & Conten
233238
}
234239

235240
type ContentfulContentTypeBoolean implements ContentfulReference & ContentfulEntry & Node @dontInfer {
236-
sys: ContentfulSys
241+
sys: ContentfulSys!
242+
metadata: ContentfulMetadata!
237243
title: String
238244
boolean: Boolean
239245
booleanLocalized: Boolean
240246
}
241247

242248
type ContentfulContentTypeDate implements ContentfulReference & ContentfulEntry & Node @dontInfer {
243-
sys: ContentfulSys
249+
sys: ContentfulSys!
250+
metadata: ContentfulMetadata!
244251
title: String
245252
date: Date @dateformat
246253
dateTime: Date @dateformat
@@ -249,44 +256,53 @@ type ContentfulContentTypeDate implements ContentfulReference & ContentfulEntry
249256
}
250257

251258
type ContentfulContentTypeLocation implements ContentfulReference & ContentfulEntry & Node @dontInfer {
252-
sys: ContentfulSys
259+
sys: ContentfulSys!
260+
metadata: ContentfulMetadata!
253261
title: String
254262
location: ContentfulLocation
255263
locationLocalized: ContentfulLocation
256264
}
257265

258266
type ContentfulContentTypeJson implements ContentfulReference & ContentfulEntry & Node @dontInfer {
259-
sys: ContentfulSys
267+
sys: ContentfulSys!
268+
metadata: ContentfulMetadata!
260269
title: String
261270
json: JSON
262271
jsonLocalized: JSON
263272
}
264273

265274
type ContentfulContentTypeRichText implements ContentfulReference & ContentfulEntry & Node @dontInfer {
266-
sys: ContentfulSys
275+
sys: ContentfulSys!
276+
metadata: ContentfulMetadata!
267277
title: String
268278
richText: ContentfulRichText
269279
richTextLocalized: ContentfulRichText
270280
richTextValidated: ContentfulRichText
271281
}
272282

273-
type ContentfulContentTypeContentReference implements ContentfulReference & ContentfulEntry & Node @dontInfer {
274-
sys: ContentfulSys
283+
type ContentfulContentTypeContentReference implements ContentfulReference & ContentfulEntry & Node @isPlaceholder @dontInfer {
284+
sys: ContentfulSys!
285+
metadata: ContentfulMetadata!
275286
title: String
276287
one: ContentfulEntry @link(by: "id", from: "one___NODE")
277288
oneLocalized: ContentfulEntry @link(by: "id", from: "oneLocalized___NODE")
278-
many: [ContentfulEntry] @link(by: "id", from: "many___NODE")
289+
many: [UnionContentfulContentReferenceNumberText] @link(by: "id", from: "many___NODE")
279290
manyLocalized: [ContentfulEntry] @link(by: "id", from: "manyLocalized___NODE")
280291
}
281292

293+
union UnionContentfulContentReferenceNumberText = ContentfulContentTypeContentReference | ContentfulContentTypeNumber | ContentfulContentTypeText
294+
295+
union UnionContentfulNumberText = ContentfulContentTypeNumber | ContentfulContentTypeText
296+
282297
type ContentfulContentTypeValidatedContentReference implements ContentfulReference & ContentfulEntry & Node @dontInfer {
283-
sys: ContentfulSys
298+
sys: ContentfulSys!
299+
metadata: ContentfulMetadata!
284300
title: String
285-
oneItemSingleType: ContentfulEntry @link(by: "id", from: "oneItemSingleType___NODE")
286-
oneItemManyTypes: ContentfulEntry @link(by: "id", from: "oneItemManyTypes___NODE")
301+
oneItemSingleType: ContentfulContentTypeText @link(by: "id", from: "oneItemSingleType___NODE")
302+
oneItemManyTypes: UnionContentfulNumberText @link(by: "id", from: "oneItemManyTypes___NODE")
287303
oneItemAllTypes: ContentfulEntry @link(by: "id", from: "oneItemAllTypes___NODE")
288-
multipleItemsSingleType: [ContentfulEntry] @link(by: "id", from: "multipleItemsSingleType___NODE")
289-
multipleItemsManyTypes: [ContentfulEntry] @link(by: "id", from: "multipleItemsManyTypes___NODE")
304+
multipleItemsSingleType: [ContentfulContentTypeText] @link(by: "id", from: "multipleItemsSingleType___NODE")
305+
multipleItemsManyTypes: [UnionContentfulNumberText] @link(by: "id", from: "multipleItemsManyTypes___NODE")
290306
multipleItemsAllTypes: [ContentfulEntry] @link(by: "id", from: "multipleItemsAllTypes___NODE")
291307
}
292308

@@ -317,7 +333,7 @@ type MarkdownWordCount {
317333
words: Int
318334
}
319335

320-
type MarkdownRemark implements Node @childOf(mimeTypes: ["text/markdown", "text/x-markdown"], types: ["ContentfulText"]) @dontInfer {
336+
type MarkdownRemark implements Node @childOf(mimeTypes: ["text/markdown", "text/x-markdown"], types: ["ContentfulText"]) @derivedTypes @dontInfer {
321337
frontmatter: MarkdownRemarkFrontmatter
322338
excerpt: String
323339
rawMarkdownBody: String
@@ -481,7 +497,7 @@ type ImageSharpResize {
481497
originalName: String
482498
}
483499

484-
type ImageSharp implements Node @childOf(mimeTypes: [], types: ["File"]) @dontInfer {
500+
type ImageSharp implements Node @childOf(types: ["File"]) @dontInfer {
485501
fixed(width: Int, height: Int, base64Width: Int, jpegProgressive: Boolean = true, pngCompressionSpeed: Int = 4, grayscale: Boolean = false, duotone: DuotoneGradient, traceSVG: Potrace, quality: Int, jpegQuality: Int, pngQuality: Int, webpQuality: Int, toFormat: ImageFormat = AUTO, toFormatBase64: ImageFormat = AUTO, cropFocus: ImageCropFocus = ATTENTION, fit: ImageFit = COVER, background: String = "rgba(0,0,0,1)", rotate: Int = 0, trim: Float = 0): ImageSharpFixed
486502
fluid(
487503
maxWidth: Int
@@ -652,7 +668,7 @@ enum GatsbyImagePlaceholder {
652668
NONE
653669
}
654670

655-
type ContentfulContentTypeContentType implements Node @dontInfer {
671+
type ContentfulContentTypeContentType implements Node @derivedTypes @dontInfer {
656672
name: String
657673
displayField: String
658674
description: String

0 commit comments

Comments
 (0)