From 9933ec019a3772eb4eba49f2e3d4f29c7b9a49bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20R=C3=B6tsch?= Date: Wed, 10 Jan 2024 11:46:10 +0100 Subject: [PATCH 01/12] perf: add new flag for nodes from external sources to prevent unnecessary data loops --- .../src/create-schema-customization.ts | 47 ++++++++++++++----- .../gatsby-source-contentful/src/normalize.ts | 2 + packages/gatsby/index.d.ts | 5 +- packages/gatsby/src/joi-schemas/joi.ts | 1 + packages/gatsby/src/schema/node-model.js | 3 ++ .../gatsby/src/schema/types/node-interface.ts | 1 + 6 files changed, 46 insertions(+), 13 deletions(-) diff --git a/packages/gatsby-source-contentful/src/create-schema-customization.ts b/packages/gatsby-source-contentful/src/create-schema-customization.ts index 265e3a7fbbac7..b231b03df5c64 100644 --- a/packages/gatsby-source-contentful/src/create-schema-customization.ts +++ b/packages/gatsby-source-contentful/src/create-schema-customization.ts @@ -2,6 +2,7 @@ import type { GatsbyNode, NodePluginSchema, CreateSchemaCustomizationArgs, + IGatsbyResolverContext, } from "gatsby" import { GraphQLFieldConfig, @@ -31,15 +32,29 @@ import type { } from "./types/contentful" import { detectMarkdownField, makeContentTypeIdMap } from "./utils" import { restrictedNodeFields } from "./config" +import { Document } from "@contentful/rich-text-types" type CreateTypes = CreateSchemaCustomizationArgs["actions"]["createTypes"] interface IContentfulGraphQLField - extends Omit>, "type"> { + extends Omit< + Partial< + GraphQLFieldConfig< + IContentfulEntry, + IGatsbyResolverContext + > + >, + "type" + > { type: string | GraphQLType id?: string } +interface IRichTextFieldStructure { + richTextData: Document + spaceId: string +} + // Contentful content type schemas const ContentfulDataTypes: Map< string, @@ -112,7 +127,18 @@ const ContentfulDataTypes: Map< [ `RichText`, (): IContentfulGraphQLField => { - return { type: `ContentfulRichText` } + return { + type: `ContentfulRichText`, + resolve: (source, args, context, info): IRichTextFieldStructure => { + const richTextData = context.defaultFieldResolver( + source, + args, + context, + info + ) + return { richTextData, spaceId: source.sys.spaceId } + }, + } }, ], ]) @@ -584,16 +610,13 @@ export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"] const makeRichTextLinksResolver = (nodeType, entityType) => async ( - source, + source: IRichTextFieldStructure, _args, context ): Promise | null> => { - const links = getRichTextEntityLinks(source, nodeType)[entityType].map( - ({ id }) => id - ) - - const node = context.nodeModel.findRootNodeAncestor(source) - if (!node) return null + const links = getRichTextEntityLinks(source.richTextData, nodeType)[ + entityType + ].map(({ id }) => id) const res = await context.nodeModel.findAll({ query: { @@ -602,7 +625,7 @@ export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"] id: { in: links, }, - spaceId: { eq: node.sys.spaceId }, + spaceId: { eq: source.spaceId }, }, }, }, @@ -678,8 +701,8 @@ export const createSchemaCustomization: GatsbyNode["createSchemaCustomization"] fields: { json: { type: `JSON`, - resolve(source) { - return source + resolve(source: IRichTextFieldStructure) { + return source.richTextData }, }, links: { diff --git a/packages/gatsby-source-contentful/src/normalize.ts b/packages/gatsby-source-contentful/src/normalize.ts index 45b7a29af6937..c9082d7f8228a 100644 --- a/packages/gatsby-source-contentful/src/normalize.ts +++ b/packages/gatsby-source-contentful/src/normalize.ts @@ -788,6 +788,7 @@ export const createNodesForContentType = ({ type: makeTypeName(contentTypeItemId, contentTypePrefix), // The content of an entry is guaranteed to be updated if and only if the .sys.updatedAt field changed contentDigest: entryItem.sys.updatedAt as string, + dontTrackInlineObjects: true, }, // https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/common-resource-attributes // https://www.contentful.com/developers/docs/references/graphql/#/reference/schema-generation/sys-field @@ -944,6 +945,7 @@ export const createAssetNodes = async ({ type: `ContentfulAsset`, // The content of an asset is guaranteed to be updated if and only if the .sys.updatedAt field changed contentDigest: assetItem.sys.updatedAt, + dontTrackInlineObjects: true, }, // https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/common-resource-attributes // https://www.contentful.com/developers/docs/references/graphql/#/reference/schema-generation/sys-field diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index ca252cbf48bc9..a42222b5d63af 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -34,6 +34,8 @@ export { export * from "gatsby-script" +export { IGatsbyResolverContext } from "./src/schema/type-definitions" + export { AdapterInit, IAdapter, @@ -1776,7 +1778,8 @@ export interface NodeInput { content?: string contentDigest: string description?: string - contentFilePath?: string + contentFilePath?: string, + dontTrackInlineObjects?: boolean } [key: string]: unknown } diff --git a/packages/gatsby/src/joi-schemas/joi.ts b/packages/gatsby/src/joi-schemas/joi.ts index cb5402fd55295..9a0c73c5828ce 100644 --- a/packages/gatsby/src/joi-schemas/joi.ts +++ b/packages/gatsby/src/joi-schemas/joi.ts @@ -177,6 +177,7 @@ export const nodeSchema: Joi.ObjectSchema = Joi.object() ignoreType: Joi.boolean(), counter: Joi.number(), contentFilePath: Joi.string(), + dontTrackInlineObjects: Joi.boolean(), }) .unknown(false), // Don't allow non-standard fields }) diff --git a/packages/gatsby/src/schema/node-model.js b/packages/gatsby/src/schema/node-model.js index b7e5824745a03..5b2501e02c2e5 100644 --- a/packages/gatsby/src/schema/node-model.js +++ b/packages/gatsby/src/schema/node-model.js @@ -963,6 +963,9 @@ const addRootNodeToInlineObject = ( const isPlainObject = _.isPlainObject(data) if (isPlainObject || _.isArray(data)) { + if (data?.internal.dontTrackInlineObjects) { + return + } if (path.has(data)) return path.add(data) diff --git a/packages/gatsby/src/schema/types/node-interface.ts b/packages/gatsby/src/schema/types/node-interface.ts index 5769947f3381e..51f414cfca1cd 100644 --- a/packages/gatsby/src/schema/types/node-interface.ts +++ b/packages/gatsby/src/schema/types/node-interface.ts @@ -27,6 +27,7 @@ const getOrCreateNodeInterface = ( owner: `String!`, type: `String!`, contentFilePath: `String`, + dontTrackInlineObjects: `Boolean`, }) // TODO: Can be removed with graphql-compose 5.11 tc.getInputTypeComposer() From 6aa66423064ef4c3e398b77b7ec0f2c9a00f02c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20R=C3=B6tsch?= Date: Wed, 10 Jan 2024 11:54:40 +0100 Subject: [PATCH 02/12] style: remove comma --- packages/gatsby/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index a42222b5d63af..5cf3513216751 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -1778,7 +1778,7 @@ export interface NodeInput { content?: string contentDigest: string description?: string - contentFilePath?: string, + contentFilePath?: string dontTrackInlineObjects?: boolean } [key: string]: unknown From 52df3fae174c523de5e9f7a6e02dd7b0385b8e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20R=C3=B6tsch?= Date: Wed, 10 Jan 2024 12:03:36 +0100 Subject: [PATCH 03/12] chore: improve rich text types --- packages/gatsby-source-contentful/src/rich-text.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-contentful/src/rich-text.ts b/packages/gatsby-source-contentful/src/rich-text.ts index bf8fc064c7d5c..64db47890a4a1 100644 --- a/packages/gatsby-source-contentful/src/rich-text.ts +++ b/packages/gatsby-source-contentful/src/rich-text.ts @@ -42,7 +42,7 @@ export function renderRichText( json, links, }: { - json: unknown + json: Document links?: unknown }, makeOptions?: MakeOptions | Options @@ -52,7 +52,7 @@ export function renderRichText( ? makeOptions(generateLinkMaps(links as IContentfulRichTextLinks)) : makeOptions - return documentToReactComponents(json as Document, options) + return documentToReactComponents(json, options) } /** From 252194574878aac76a7161e1b98c7aaef5cd13b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20R=C3=B6tsch?= Date: Wed, 10 Jan 2024 12:04:05 +0100 Subject: [PATCH 04/12] fix: check for the new flag on nodes only --- packages/gatsby/src/schema/node-model.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/src/schema/node-model.js b/packages/gatsby/src/schema/node-model.js index 5b2501e02c2e5..512b9b36958f0 100644 --- a/packages/gatsby/src/schema/node-model.js +++ b/packages/gatsby/src/schema/node-model.js @@ -963,7 +963,7 @@ const addRootNodeToInlineObject = ( const isPlainObject = _.isPlainObject(data) if (isPlainObject || _.isArray(data)) { - if (data?.internal.dontTrackInlineObjects) { + if (isNode && data.internal.dontTrackInlineObjects) { return } if (path.has(data)) return From 1d619b1383a72e9f7dc846fee2db9f4b3bbf35c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20R=C3=B6tsch?= Date: Wed, 10 Jan 2024 12:10:46 +0100 Subject: [PATCH 05/12] Revert "chore: improve rich text types" This reverts commit 52df3fae174c523de5e9f7a6e02dd7b0385b8e64. --- packages/gatsby-source-contentful/src/rich-text.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-source-contentful/src/rich-text.ts b/packages/gatsby-source-contentful/src/rich-text.ts index 64db47890a4a1..bf8fc064c7d5c 100644 --- a/packages/gatsby-source-contentful/src/rich-text.ts +++ b/packages/gatsby-source-contentful/src/rich-text.ts @@ -42,7 +42,7 @@ export function renderRichText( json, links, }: { - json: Document + json: unknown links?: unknown }, makeOptions?: MakeOptions | Options @@ -52,7 +52,7 @@ export function renderRichText( ? makeOptions(generateLinkMaps(links as IContentfulRichTextLinks)) : makeOptions - return documentToReactComponents(json, options) + return documentToReactComponents(json as Document, options) } /** From 66ed27ab37baa175ce993eb8dbb7f48ee2ba1d99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20R=C3=B6tsch?= Date: Wed, 10 Jan 2024 13:58:53 +0100 Subject: [PATCH 06/12] test: update snapshots for new dontTrackInlineObjects flag --- .../__snapshots__/create-schema-customization.js.snap | 3 +++ .../src/schema/__tests__/__snapshots__/build-schema.js.snap | 4 ++++ .../src/schema/__tests__/__snapshots__/rebuild-schema.js.snap | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/packages/gatsby-source-contentful/src/__tests__/__snapshots__/create-schema-customization.js.snap b/packages/gatsby-source-contentful/src/__tests__/__snapshots__/create-schema-customization.js.snap index d8dc2396e549f..65368dbde35b7 100644 --- a/packages/gatsby-source-contentful/src/__tests__/__snapshots__/create-schema-customization.js.snap +++ b/packages/gatsby-source-contentful/src/__tests__/__snapshots__/create-schema-customization.js.snap @@ -738,12 +738,15 @@ Ignored if layout = FLUID.", }, "linkedFrom": "ContentfulLinkedFrom", "richText": Object { + "resolve": [Function], "type": "ContentfulRichText", }, "richTextLocalized": Object { + "resolve": [Function], "type": "ContentfulRichText", }, "richTextValidated": Object { + "resolve": [Function], "type": "ContentfulRichText", }, "sys": Object { diff --git a/packages/gatsby/src/schema/__tests__/__snapshots__/build-schema.js.snap b/packages/gatsby/src/schema/__tests__/__snapshots__/build-schema.js.snap index afeb90d39d48f..05dfa8e4e0860 100644 --- a/packages/gatsby/src/schema/__tests__/__snapshots__/build-schema.js.snap +++ b/packages/gatsby/src/schema/__tests__/__snapshots__/build-schema.js.snap @@ -2016,6 +2016,7 @@ type Internal { owner: String! type: String! contentFilePath: String + dontTrackInlineObjects: Boolean } \\"\\"\\" @@ -2356,6 +2357,7 @@ input InternalFilterInput { owner: StringQueryOperatorInput type: StringQueryOperatorInput contentFilePath: StringQueryOperatorInput + dontTrackInlineObjects: BooleanQueryOperatorInput } input BooleanQueryOperatorInput { @@ -2452,6 +2454,7 @@ input InternalFieldSelector { owner: FieldSelectorEnum type: FieldSelectorEnum contentFilePath: FieldSelectorEnum + dontTrackInlineObjects: FieldSelectorEnum } type FileGroupConnection { @@ -2566,6 +2569,7 @@ input InternalSortInput { owner: SortOrderEnum type: SortOrderEnum contentFilePath: SortOrderEnum + dontTrackInlineObjects: SortOrderEnum } type DirectoryConnection { diff --git a/packages/gatsby/src/schema/__tests__/__snapshots__/rebuild-schema.js.snap b/packages/gatsby/src/schema/__tests__/__snapshots__/rebuild-schema.js.snap index e8ca70911a884..a02f3b0c850ba 100644 --- a/packages/gatsby/src/schema/__tests__/__snapshots__/rebuild-schema.js.snap +++ b/packages/gatsby/src/schema/__tests__/__snapshots__/rebuild-schema.js.snap @@ -215,6 +215,7 @@ type Internal { owner: String! type: String! contentFilePath: String + dontTrackInlineObjects: Boolean } \\"\\"\\" @@ -555,6 +556,7 @@ input InternalFilterInput { owner: StringQueryOperatorInput type: StringQueryOperatorInput contentFilePath: StringQueryOperatorInput + dontTrackInlineObjects: BooleanQueryOperatorInput } input BooleanQueryOperatorInput { @@ -651,6 +653,7 @@ input InternalFieldSelector { owner: FieldSelectorEnum type: FieldSelectorEnum contentFilePath: FieldSelectorEnum + dontTrackInlineObjects: FieldSelectorEnum } type FileGroupConnection { @@ -765,6 +768,7 @@ input InternalSortInput { owner: SortOrderEnum type: SortOrderEnum contentFilePath: SortOrderEnum + dontTrackInlineObjects: SortOrderEnum } type DirectoryConnection { From 2ecfc779b5b4e3ea4e6cbc07e0bf22fec5e36c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20R=C3=B6tsch?= Date: Thu, 25 Jan 2024 12:05:01 +0100 Subject: [PATCH 07/12] refactor: rename from dontTrackInlineObjects to trackInlineObjects --- packages/gatsby-source-contentful/src/normalize.ts | 4 ++-- packages/gatsby/index.d.ts | 2 +- packages/gatsby/src/joi-schemas/joi.ts | 2 +- .../schema/__tests__/__snapshots__/build-schema.js.snap | 8 ++++---- .../schema/__tests__/__snapshots__/rebuild-schema.js.snap | 8 ++++---- packages/gatsby/src/schema/node-model.js | 2 +- packages/gatsby/src/schema/types/node-interface.ts | 2 +- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/gatsby-source-contentful/src/normalize.ts b/packages/gatsby-source-contentful/src/normalize.ts index c9082d7f8228a..31c1eaf39f74e 100644 --- a/packages/gatsby-source-contentful/src/normalize.ts +++ b/packages/gatsby-source-contentful/src/normalize.ts @@ -788,7 +788,7 @@ export const createNodesForContentType = ({ type: makeTypeName(contentTypeItemId, contentTypePrefix), // The content of an entry is guaranteed to be updated if and only if the .sys.updatedAt field changed contentDigest: entryItem.sys.updatedAt as string, - dontTrackInlineObjects: true, + trackInlineObjects: false, }, // https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/common-resource-attributes // https://www.contentful.com/developers/docs/references/graphql/#/reference/schema-generation/sys-field @@ -945,7 +945,7 @@ export const createAssetNodes = async ({ type: `ContentfulAsset`, // The content of an asset is guaranteed to be updated if and only if the .sys.updatedAt field changed contentDigest: assetItem.sys.updatedAt, - dontTrackInlineObjects: true, + trackInlineObjects: false, }, // https://www.contentful.com/developers/docs/references/content-delivery-api/#/introduction/common-resource-attributes // https://www.contentful.com/developers/docs/references/graphql/#/reference/schema-generation/sys-field diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index 5cf3513216751..42eba01c349c6 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -1779,7 +1779,7 @@ export interface NodeInput { contentDigest: string description?: string contentFilePath?: string - dontTrackInlineObjects?: boolean + trackInlineObjects?: boolean } [key: string]: unknown } diff --git a/packages/gatsby/src/joi-schemas/joi.ts b/packages/gatsby/src/joi-schemas/joi.ts index 9a0c73c5828ce..352e31ee49899 100644 --- a/packages/gatsby/src/joi-schemas/joi.ts +++ b/packages/gatsby/src/joi-schemas/joi.ts @@ -177,7 +177,7 @@ export const nodeSchema: Joi.ObjectSchema = Joi.object() ignoreType: Joi.boolean(), counter: Joi.number(), contentFilePath: Joi.string(), - dontTrackInlineObjects: Joi.boolean(), + trackInlineObjects: Joi.boolean(), }) .unknown(false), // Don't allow non-standard fields }) diff --git a/packages/gatsby/src/schema/__tests__/__snapshots__/build-schema.js.snap b/packages/gatsby/src/schema/__tests__/__snapshots__/build-schema.js.snap index 05dfa8e4e0860..1cbf2b5b40dcd 100644 --- a/packages/gatsby/src/schema/__tests__/__snapshots__/build-schema.js.snap +++ b/packages/gatsby/src/schema/__tests__/__snapshots__/build-schema.js.snap @@ -2016,7 +2016,7 @@ type Internal { owner: String! type: String! contentFilePath: String - dontTrackInlineObjects: Boolean + trackInlineObjects: Boolean } \\"\\"\\" @@ -2357,7 +2357,7 @@ input InternalFilterInput { owner: StringQueryOperatorInput type: StringQueryOperatorInput contentFilePath: StringQueryOperatorInput - dontTrackInlineObjects: BooleanQueryOperatorInput + trackInlineObjects: BooleanQueryOperatorInput } input BooleanQueryOperatorInput { @@ -2454,7 +2454,7 @@ input InternalFieldSelector { owner: FieldSelectorEnum type: FieldSelectorEnum contentFilePath: FieldSelectorEnum - dontTrackInlineObjects: FieldSelectorEnum + trackInlineObjects: FieldSelectorEnum } type FileGroupConnection { @@ -2569,7 +2569,7 @@ input InternalSortInput { owner: SortOrderEnum type: SortOrderEnum contentFilePath: SortOrderEnum - dontTrackInlineObjects: SortOrderEnum + trackInlineObjects: SortOrderEnum } type DirectoryConnection { diff --git a/packages/gatsby/src/schema/__tests__/__snapshots__/rebuild-schema.js.snap b/packages/gatsby/src/schema/__tests__/__snapshots__/rebuild-schema.js.snap index a02f3b0c850ba..a59ab4f0debc2 100644 --- a/packages/gatsby/src/schema/__tests__/__snapshots__/rebuild-schema.js.snap +++ b/packages/gatsby/src/schema/__tests__/__snapshots__/rebuild-schema.js.snap @@ -215,7 +215,7 @@ type Internal { owner: String! type: String! contentFilePath: String - dontTrackInlineObjects: Boolean + trackInlineObjects: Boolean } \\"\\"\\" @@ -556,7 +556,7 @@ input InternalFilterInput { owner: StringQueryOperatorInput type: StringQueryOperatorInput contentFilePath: StringQueryOperatorInput - dontTrackInlineObjects: BooleanQueryOperatorInput + trackInlineObjects: BooleanQueryOperatorInput } input BooleanQueryOperatorInput { @@ -653,7 +653,7 @@ input InternalFieldSelector { owner: FieldSelectorEnum type: FieldSelectorEnum contentFilePath: FieldSelectorEnum - dontTrackInlineObjects: FieldSelectorEnum + trackInlineObjects: FieldSelectorEnum } type FileGroupConnection { @@ -768,7 +768,7 @@ input InternalSortInput { owner: SortOrderEnum type: SortOrderEnum contentFilePath: SortOrderEnum - dontTrackInlineObjects: SortOrderEnum + trackInlineObjects: SortOrderEnum } type DirectoryConnection { diff --git a/packages/gatsby/src/schema/node-model.js b/packages/gatsby/src/schema/node-model.js index 512b9b36958f0..59e1fa0c19382 100644 --- a/packages/gatsby/src/schema/node-model.js +++ b/packages/gatsby/src/schema/node-model.js @@ -963,7 +963,7 @@ const addRootNodeToInlineObject = ( const isPlainObject = _.isPlainObject(data) if (isPlainObject || _.isArray(data)) { - if (isNode && data.internal.dontTrackInlineObjects) { + if (isNode && data.internal.trackInlineObjects === false) { return } if (path.has(data)) return diff --git a/packages/gatsby/src/schema/types/node-interface.ts b/packages/gatsby/src/schema/types/node-interface.ts index 51f414cfca1cd..4f5f6019a2b99 100644 --- a/packages/gatsby/src/schema/types/node-interface.ts +++ b/packages/gatsby/src/schema/types/node-interface.ts @@ -27,7 +27,7 @@ const getOrCreateNodeInterface = ( owner: `String!`, type: `String!`, contentFilePath: `String`, - dontTrackInlineObjects: `Boolean`, + trackInlineObjects: `Boolean`, }) // TODO: Can be removed with graphql-compose 5.11 tc.getInputTypeComposer() From 8ddeb1a26cc536a7c67cd7a3494b27a22fa0cb68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20R=C3=B6tsch?= Date: Thu, 25 Jan 2024 12:25:31 +0100 Subject: [PATCH 08/12] refactor: move check for inline object tracking to be executed earlier --- packages/gatsby/src/schema/node-model.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/gatsby/src/schema/node-model.js b/packages/gatsby/src/schema/node-model.js index 59e1fa0c19382..649137161b74d 100644 --- a/packages/gatsby/src/schema/node-model.js +++ b/packages/gatsby/src/schema/node-model.js @@ -498,6 +498,9 @@ class LocalNodeModel { * @param {Node} node Root Node */ trackInlineObjectsInRootNode(node) { + if (node.internal.trackInlineObjects === false) { + return + } if (!this._trackedRootNodes.has(node)) { addRootNodeToInlineObject( this._rootNodeMap, @@ -963,9 +966,6 @@ const addRootNodeToInlineObject = ( const isPlainObject = _.isPlainObject(data) if (isPlainObject || _.isArray(data)) { - if (isNode && data.internal.trackInlineObjects === false) { - return - } if (path.has(data)) return path.add(data) From 792f14e72a61b2ffde9f211754a70d323a3ef804 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 20 Feb 2024 13:16:33 +0100 Subject: [PATCH 09/12] feat: fail early if used gatsby version is too old --- packages/gatsby-source-contentful/src/gatsby-node.ts | 12 ++++++++++++ packages/gatsby-source-contentful/src/report.ts | 6 ++++++ packages/gatsby/index.d.ts | 1 + packages/gatsby/scripts/output-api-file.js | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-source-contentful/src/gatsby-node.ts b/packages/gatsby-source-contentful/src/gatsby-node.ts index de198c55a9466..b969ef669ba9b 100644 --- a/packages/gatsby-source-contentful/src/gatsby-node.ts +++ b/packages/gatsby-source-contentful/src/gatsby-node.ts @@ -2,6 +2,7 @@ import type { GatsbyNode } from "gatsby" import origFetch from "node-fetch" import fetchRetry from "@vercel/fetch-retry" import { polyfillImageServiceDevRoutes } from "gatsby-plugin-utils/polyfill-remote-file" +import { hasFeature } from "gatsby-plugin-utils/has-feature" import { CODES } from "./report" import { maskText } from "./plugin-options" @@ -47,6 +48,17 @@ export const onPreInit: GatsbyNode["onPreInit"] = async ( { store, reporter, actions }, pluginOptions ) => { + // gatsby version is too old + if (!hasFeature(`track-inline-object-opt-out`)) { + reporter.panic({ + id: CODES.GatsbyPluginMissing, + context: { + // TODO update message to reflect the actual version with track-inline-object-opt-out support + sourceMessage: `Used gatsby version is too old and doesn't support required features. Please update to gatsby@>=5.X.0`, + }, + }) + } + // if gatsby-plugin-image is not installed try { await import(`gatsby-plugin-image/graphql-utils.js`) diff --git a/packages/gatsby-source-contentful/src/report.ts b/packages/gatsby-source-contentful/src/report.ts index 1de95e68dde21..dbd796ae78c3e 100644 --- a/packages/gatsby-source-contentful/src/report.ts +++ b/packages/gatsby-source-contentful/src/report.ts @@ -10,6 +10,7 @@ export const CODES = { ContentTypesMissing: `111006`, FetchTags: `111007`, GenericContentfulError: `111008`, + GatsbyTooOld: `111009`, } interface IErrorMap { @@ -57,4 +58,9 @@ export const ERROR_MAP: IErrorMap = { level: `ERROR`, category: `THIRD_PARTY`, }, + [CODES.GatsbyTooOld]: { + text: context => context.sourceMessage, + level: `ERROR`, + category: `USER`, + }, } diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index 42eba01c349c6..f4beecf3092a6 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -23,6 +23,7 @@ export type AvailableFeatures = | "content-file-path" | "stateful-source-nodes" | "adapters" + | "track-inline-object-opt-out" export { Link, diff --git a/packages/gatsby/scripts/output-api-file.js b/packages/gatsby/scripts/output-api-file.js index 8f3cf1b5f7c32..826a04429c123 100644 --- a/packages/gatsby/scripts/output-api-file.js +++ b/packages/gatsby/scripts/output-api-file.js @@ -41,7 +41,7 @@ async function outputFile() { }, {}) /** @type {Array} */ - output.features = ["image-cdn", "graphql-typegen", "content-file-path", "slices", "stateful-source-nodes", "adapters"]; + output.features = ["image-cdn", "graphql-typegen", "content-file-path", "slices", "stateful-source-nodes", "adapters", "track-inline-object-opt-out"]; return fs.writeFile( path.resolve(OUTPUT_FILE_NAME), From 0a5b048effd7ade477ea4ad26ee6b035563f5684 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 20 Feb 2024 16:43:05 +0100 Subject: [PATCH 10/12] fix: export types from dist not src --- packages/gatsby/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby/index.d.ts b/packages/gatsby/index.d.ts index f4beecf3092a6..7e33201c4c329 100644 --- a/packages/gatsby/index.d.ts +++ b/packages/gatsby/index.d.ts @@ -35,7 +35,7 @@ export { export * from "gatsby-script" -export { IGatsbyResolverContext } from "./src/schema/type-definitions" +export { IGatsbyResolverContext } from "./dist/schema/type-definitions" export { AdapterInit, From f679886c10c9ed4f116fe4bed9636f9122b4c3c5 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 20 Feb 2024 18:34:39 +0100 Subject: [PATCH 11/12] test: update apis.json snapshot --- packages/gatsby/scripts/__tests__/api.js | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/gatsby/scripts/__tests__/api.js b/packages/gatsby/scripts/__tests__/api.js index dc1c6ce7ca41e..665dd8db02cb0 100644 --- a/packages/gatsby/scripts/__tests__/api.js +++ b/packages/gatsby/scripts/__tests__/api.js @@ -37,6 +37,7 @@ it("generates the expected api output", done => { "slices", "stateful-source-nodes", "adapters", + "track-inline-object-opt-out", ], "node": Object { "createPages": Object {}, From 3b01b9ce0d62233f6f2a1121883dcdc41ab7130d Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Tue, 20 Feb 2024 19:39:35 +0100 Subject: [PATCH 12/12] Update config.yml --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b9d39a3f86996..320c3de5f3488 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -518,7 +518,7 @@ jobs: nvm install 18.0.0 nvm alias default 18.0.0 nvm use 18.0.0 - choco install yarn + choco install yarn -y - run: name: Rebuild packages for windows command: |