Skip to content

Commit

Permalink
feat: use union for reference fields with validation (#31395)
Browse files Browse the repository at this point in the history
Also:

* test: add unit tests for schema customization

* fix: rich text inline rendering

* test: update e2e test schema dump
  • Loading branch information
axe312ger committed Jan 6, 2022
1 parent 0be1d7b commit a5715aa
Show file tree
Hide file tree
Showing 9 changed files with 1,820 additions and 56 deletions.
88 changes: 52 additions & 36 deletions e2e-tests/contentful/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ type Directory implements Node @dontInfer {
type Site implements Node @dontInfer {
buildTime: Date @dateformat
siteMetadata: SiteSiteMetadata
port: Int
host: String
polyfill: Boolean
pathPrefix: String
jsxRuntime: String
Expand Down Expand Up @@ -124,12 +122,11 @@ type SiteBuildMetadata implements Node @dontInfer {

interface ContentfulReference implements Node {
id: ID!
sys: ContentfulSys
sys: ContentfulSys!
}

type ContentfulSys {
type ContentfulSys implements Node @dontInfer {
type: String!
id: String!
spaceId: String!
environmentId: String!
contentType: ContentfulContentType @link(by: "id", from: "contentType___NODE")
Expand All @@ -145,13 +142,27 @@ type ContentfulContentType implements Node @dontInfer {
description: String!
}

interface ContentfulEntry implements Node {
interface ContentfulEntry implements ContentfulReference & Node {
id: ID!
sys: ContentfulSys
sys: ContentfulSys!
metadata: ContentfulMetadata!
}

type ContentfulMetadata @dontInfer {
tags: [ContentfulTag]! @link(by: "id", from: "tags___NODE")
}

type ContentfulTag implements Node @dontInfer {
name: String!
contentful_id: String!
}

type ContentfulAssetFields @dontInfer {
localFile: File @link(by: "id")
}

type ContentfulAsset implements ContentfulReference & Node @dontInfer {
sys: ContentfulSys
sys: ContentfulSys!
title: String
description: String
contentType: String
Expand All @@ -163,15 +174,6 @@ type ContentfulAsset implements ContentfulReference & Node @dontInfer {
fields: ContentfulAssetFields
}

type ContentfulAssetFields {
localFile: String
}

type ContentfulTag implements Node @dontInfer {
name: String!
contentful_id: String!
}

type ContentfulRichTextAssets {
block: [ContentfulAsset]!
hyperlink: [ContentfulAsset]!
Expand Down Expand Up @@ -203,7 +205,8 @@ type ContentfulText implements Node @dontInfer {
}

type ContentfulContentTypeNumber implements ContentfulReference & ContentfulEntry & Node @dontInfer {
sys: ContentfulSys
sys: ContentfulSys!
metadata: ContentfulMetadata!
title: String
integer: Int
integerLocalized: Int
Expand All @@ -212,7 +215,8 @@ type ContentfulContentTypeNumber implements ContentfulReference & ContentfulEntr
}

type ContentfulContentTypeText implements ContentfulReference & ContentfulEntry & Node @dontInfer {
sys: ContentfulSys
sys: ContentfulSys!
metadata: ContentfulMetadata!
title: String
short: String
shortLocalized: String
Expand All @@ -224,7 +228,8 @@ type ContentfulContentTypeText implements ContentfulReference & ContentfulEntry
}

type ContentfulContentTypeMediaReference implements ContentfulReference & ContentfulEntry & Node @dontInfer {
sys: ContentfulSys
sys: ContentfulSys!
metadata: ContentfulMetadata!
title: String
one: ContentfulAsset @link(by: "id", from: "one___NODE")
oneLocalized: ContentfulAsset @link(by: "id", from: "oneLocalized___NODE")
Expand All @@ -233,14 +238,16 @@ type ContentfulContentTypeMediaReference implements ContentfulReference & Conten
}

type ContentfulContentTypeBoolean implements ContentfulReference & ContentfulEntry & Node @dontInfer {
sys: ContentfulSys
sys: ContentfulSys!
metadata: ContentfulMetadata!
title: String
boolean: Boolean
booleanLocalized: Boolean
}

type ContentfulContentTypeDate implements ContentfulReference & ContentfulEntry & Node @dontInfer {
sys: ContentfulSys
sys: ContentfulSys!
metadata: ContentfulMetadata!
title: String
date: Date @dateformat
dateTime: Date @dateformat
Expand All @@ -249,44 +256,53 @@ type ContentfulContentTypeDate implements ContentfulReference & ContentfulEntry
}

type ContentfulContentTypeLocation implements ContentfulReference & ContentfulEntry & Node @dontInfer {
sys: ContentfulSys
sys: ContentfulSys!
metadata: ContentfulMetadata!
title: String
location: ContentfulLocation
locationLocalized: ContentfulLocation
}

type ContentfulContentTypeJson implements ContentfulReference & ContentfulEntry & Node @dontInfer {
sys: ContentfulSys
sys: ContentfulSys!
metadata: ContentfulMetadata!
title: String
json: JSON
jsonLocalized: JSON
}

type ContentfulContentTypeRichText implements ContentfulReference & ContentfulEntry & Node @dontInfer {
sys: ContentfulSys
sys: ContentfulSys!
metadata: ContentfulMetadata!
title: String
richText: ContentfulRichText
richTextLocalized: ContentfulRichText
richTextValidated: ContentfulRichText
}

type ContentfulContentTypeContentReference implements ContentfulReference & ContentfulEntry & Node @dontInfer {
sys: ContentfulSys
type ContentfulContentTypeContentReference implements ContentfulReference & ContentfulEntry & Node @isPlaceholder @dontInfer {
sys: ContentfulSys!
metadata: ContentfulMetadata!
title: String
one: ContentfulEntry @link(by: "id", from: "one___NODE")
oneLocalized: ContentfulEntry @link(by: "id", from: "oneLocalized___NODE")
many: [ContentfulEntry] @link(by: "id", from: "many___NODE")
many: [UnionContentfulContentReferenceNumberText] @link(by: "id", from: "many___NODE")
manyLocalized: [ContentfulEntry] @link(by: "id", from: "manyLocalized___NODE")
}

union UnionContentfulContentReferenceNumberText = ContentfulContentTypeContentReference | ContentfulContentTypeNumber | ContentfulContentTypeText

union UnionContentfulNumberText = ContentfulContentTypeNumber | ContentfulContentTypeText

type ContentfulContentTypeValidatedContentReference implements ContentfulReference & ContentfulEntry & Node @dontInfer {
sys: ContentfulSys
sys: ContentfulSys!
metadata: ContentfulMetadata!
title: String
oneItemSingleType: ContentfulEntry @link(by: "id", from: "oneItemSingleType___NODE")
oneItemManyTypes: ContentfulEntry @link(by: "id", from: "oneItemManyTypes___NODE")
oneItemSingleType: ContentfulContentTypeText @link(by: "id", from: "oneItemSingleType___NODE")
oneItemManyTypes: UnionContentfulNumberText @link(by: "id", from: "oneItemManyTypes___NODE")
oneItemAllTypes: ContentfulEntry @link(by: "id", from: "oneItemAllTypes___NODE")
multipleItemsSingleType: [ContentfulEntry] @link(by: "id", from: "multipleItemsSingleType___NODE")
multipleItemsManyTypes: [ContentfulEntry] @link(by: "id", from: "multipleItemsManyTypes___NODE")
multipleItemsSingleType: [ContentfulContentTypeText] @link(by: "id", from: "multipleItemsSingleType___NODE")
multipleItemsManyTypes: [UnionContentfulNumberText] @link(by: "id", from: "multipleItemsManyTypes___NODE")
multipleItemsAllTypes: [ContentfulEntry] @link(by: "id", from: "multipleItemsAllTypes___NODE")
}

Expand Down Expand Up @@ -317,7 +333,7 @@ type MarkdownWordCount {
words: Int
}

type MarkdownRemark implements Node @childOf(mimeTypes: ["text/markdown", "text/x-markdown"], types: ["ContentfulText"]) @dontInfer {
type MarkdownRemark implements Node @childOf(mimeTypes: ["text/markdown", "text/x-markdown"], types: ["ContentfulText"]) @derivedTypes @dontInfer {
frontmatter: MarkdownRemarkFrontmatter
excerpt: String
rawMarkdownBody: String
Expand Down Expand Up @@ -481,7 +497,7 @@ type ImageSharpResize {
originalName: String
}

type ImageSharp implements Node @childOf(mimeTypes: [], types: ["File"]) @dontInfer {
type ImageSharp implements Node @childOf(types: ["File"]) @dontInfer {
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
fluid(
maxWidth: Int
Expand Down Expand Up @@ -652,7 +668,7 @@ enum GatsbyImagePlaceholder {
NONE
}

type ContentfulContentTypeContentType implements Node @dontInfer {
type ContentfulContentTypeContentType implements Node @derivedTypes @dontInfer {
name: String
displayField: String
description: String
Expand Down
Loading

0 comments on commit a5715aa

Please sign in to comment.