Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: align Rich Text field structure to Contentful GraphQL API #31122

Conversation

axe312ger
Copy link
Collaborator

This converts the Gatsby Rich Text field type structure to the same as the Contentful GraphQL API uses.

Old schema

type ContentfulRichTextRichText {
  raw: String
  references: [ContentfulAssetContentfulContentReferenceContentfulLocationContentfulTextUnion] @link(by: "id", from: "references___NODE")
}
union ContentfulAssetContentfulContentReferenceContentfulLocationContentfulTextUnion = ContentfulAsset | ContentfulContentReference | ContentfulLocation | ContentfulText

New schema

type ContentfulNodeTypeRichText @dontInfer {
  json: JSON
  links: ContentfulNodeTypeRichTextLinks
}

type ContentfulNodeTypeRichTextLinks {
  assets: ContentfulNodeTypeRichTextAssets
  entries: ContentfulNodeTypeRichTextEntries
}

type ContentfulNodeTypeRichTextAssets {
  block: [ContentfulAsset]!
  hyperlink: [ContentfulAsset]!
}

type ContentfulNodeTypeRichTextEntries {
  inline: [ContentfulEntry]!
  block: [ContentfulEntry]!
  hyperlink: [ContentfulEntry]!
}

Rendering changes

Instead of passing your option object into renderRichText() you now pass a option factory:

-const options = {
+const makeOptions = ({ assetBlockMap, entryBlockMap, entryInlineMap }) => ({
    [BLOCKS.EMBEDDED_ENTRY]: node => {
-      const entry = node?.data?.target
+      const entry = entryBlockMap.get(node?.data?.target?.sys.id)
    }
-<div>{renderRichText(richText, options)}</div>
+<div>{renderRichText(richText, makeOptions)}</div>

@axe312ger axe312ger added breaking change If implemented, this proposed work would break functionality for older versions of Gatsby topic: source-contentful Related to Gatsby's integration with Contentful labels Apr 29, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Apr 29, 2021
@axe312ger axe312ger removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Apr 29, 2021
@axe312ger axe312ger force-pushed the feat/contentful-schema-generation branch from 6a445eb to ddea54d Compare May 5, 2021 10:29
@axe312ger axe312ger force-pushed the refactor/contentful-align-rich-text-structure branch from d4d6d8f to f204f2c Compare May 5, 2021 10:30
@axe312ger axe312ger merged commit 6e5a45b into feat/contentful-schema-generation May 5, 2021
@axe312ger axe312ger deleted the refactor/contentful-align-rich-text-structure branch May 5, 2021 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change If implemented, this proposed work would break functionality for older versions of Gatsby topic: source-contentful Related to Gatsby's integration with Contentful
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant