From 17a3f9f69ae2710f4aeef27603226281f2713281 Mon Sep 17 00:00:00 2001 From: Vladimir Razuvaev Date: Tue, 28 Sep 2021 19:31:12 +0700 Subject: [PATCH] feat(gatsby): drop SitePage inference and schema update (#33319) * feat(gatsby): drop SitePage inference and schema update * fix cli integration tests * add missing field to built-it SitePage type * update snapshots * correct link between nodes * infer -> dontInfer * trigger tests re-run * trigger tests re-run * Restore `assignChangedPages` --- .../gatsby-cli/__tests__/build.js | 1 - .../gatsby-cli/__tests__/develop.js | 1 - .../gatsby-cli/__tests__/repl.js | 1 - packages/gatsby/src/bootstrap/index.ts | 3 - .../__snapshots__/build-schema.js.snap | 83 +++++-- .../__tests__/__snapshots__/print.js.snap | 3 + .../__snapshots__/rebuild-schema.js.snap | 83 +++++-- .../src/schema/__tests__/build-schema.js | 2 + .../src/schema/__tests__/rebuild-schema.js | 4 +- .../schema/__tests__/rebuild-sitepage-type.js | 216 ------------------ .../gatsby/src/schema/graphql-engine/entry.ts | 2 +- packages/gatsby/src/schema/index.js | 60 +---- packages/gatsby/src/schema/schema.js | 54 +---- .../gatsby/src/schema/types/built-in-types.ts | 3 +- packages/gatsby/src/services/index.ts | 1 - .../rebuild-schema-with-site-pages.ts | 14 -- .../src/state-machines/data-layer/index.ts | 20 +- .../src/state-machines/data-layer/services.ts | 2 - .../state-machines/query-running/services.ts | 2 - .../gatsby/src/utils/worker/child/schema.ts | 2 +- 20 files changed, 148 insertions(+), 409 deletions(-) delete mode 100644 packages/gatsby/src/schema/__tests__/rebuild-sitepage-type.js delete mode 100644 packages/gatsby/src/services/rebuild-schema-with-site-pages.ts diff --git a/integration-tests/gatsby-cli/__tests__/build.js b/integration-tests/gatsby-cli/__tests__/build.js index 724150a93662a..e31a54dee070a 100644 --- a/integration-tests/gatsby-cli/__tests__/build.js +++ b/integration-tests/gatsby-cli/__tests__/build.js @@ -25,7 +25,6 @@ describe(`gatsby build`, () => { logs.should.contain(`success createPages`) logs.should.contain(`success createPagesStatefully`) logs.should.contain(`success onPreExtractQueries`) - logs.should.contain(`success update schema`) logs.should.contain(`success extract queries from components`) logs.should.contain(`success write out requires`) logs.should.contain(`success write out redirect data`) diff --git a/integration-tests/gatsby-cli/__tests__/develop.js b/integration-tests/gatsby-cli/__tests__/develop.js index 47e62188fc504..db41335abe2f7 100644 --- a/integration-tests/gatsby-cli/__tests__/develop.js +++ b/integration-tests/gatsby-cli/__tests__/develop.js @@ -39,7 +39,6 @@ describe(`gatsby develop`, () => { logs.should.contain(`success createPages`) logs.should.contain(`success createPagesStatefully`) logs.should.contain(`success onPreExtractQueries`) - logs.should.contain(`success update schema`) logs.should.contain(`success extract queries from components`) logs.should.contain(`success write out requires`) logs.should.contain(`success write out redirect data`) diff --git a/integration-tests/gatsby-cli/__tests__/repl.js b/integration-tests/gatsby-cli/__tests__/repl.js index 203345e364c49..9eec28120ea7f 100644 --- a/integration-tests/gatsby-cli/__tests__/repl.js +++ b/integration-tests/gatsby-cli/__tests__/repl.js @@ -34,7 +34,6 @@ describe(`gatsby repl`, () => { logs.should.contain(`success createPages`) logs.should.contain(`success createPagesStatefully`) logs.should.contain(`success onPreExtractQueries`) - logs.should.contain(`success update schema`) logs.should.contain(`success extract queries from components`) logs.should.contain(`success write out redirect data`) logs.should.contain(`success onPostBootstrap`) diff --git a/packages/gatsby/src/bootstrap/index.ts b/packages/gatsby/src/bootstrap/index.ts index 64cebb88f677b..fe3768df909a1 100644 --- a/packages/gatsby/src/bootstrap/index.ts +++ b/packages/gatsby/src/bootstrap/index.ts @@ -11,7 +11,6 @@ import { extractQueries, writeOutRedirects, postBootstrap, - rebuildSchemaWithSitePage, } from "../services" import { Runner, createGraphQLRunner } from "./create-graphql-runner" import { globalTracer } from "opentracing" @@ -70,8 +69,6 @@ export async function bootstrap( await handleStalePageData(parentSpan) - await rebuildSchemaWithSitePage(context) - if (process.env.GATSBY_EXPERIMENTAL_PARALLEL_QUERY_RUNNING) { savePartialStateToDisk([`inferenceMetadata`]) 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 c6027a49f6d49..551fc1c293fb2 100644 --- a/packages/gatsby/src/schema/__tests__/__snapshots__/build-schema.js.snap +++ b/packages/gatsby/src/schema/__tests__/__snapshots__/build-schema.js.snap @@ -422,6 +422,7 @@ type SitePage implements Node { componentChunkName: String! matchPath: String pageContext: JSON + pluginCreator: SitePlugin id: ID! parent: Node children: [Node!]! @@ -482,7 +483,7 @@ type Query { allSite(filter: SiteFilterInput, sort: SiteSortInput, skip: Int, limit: Int): SiteConnection! siteFunction(functionRoute: StringQueryOperatorInput, pluginName: StringQueryOperatorInput, originalAbsoluteFilePath: StringQueryOperatorInput, originalRelativeFilePath: StringQueryOperatorInput, relativeCompiledFilePath: StringQueryOperatorInput, absoluteCompiledFilePath: StringQueryOperatorInput, matchPath: StringQueryOperatorInput, id: StringQueryOperatorInput, parent: NodeFilterInput, children: NodeFilterListInput, internal: InternalFilterInput): SiteFunction allSiteFunction(filter: SiteFunctionFilterInput, sort: SiteFunctionSortInput, skip: Int, limit: Int): SiteFunctionConnection! - sitePage(path: StringQueryOperatorInput, component: StringQueryOperatorInput, internalComponentName: StringQueryOperatorInput, componentChunkName: StringQueryOperatorInput, matchPath: StringQueryOperatorInput, pageContext: JSONQueryOperatorInput, id: StringQueryOperatorInput, parent: NodeFilterInput, children: NodeFilterListInput, internal: InternalFilterInput): SitePage + sitePage(path: StringQueryOperatorInput, component: StringQueryOperatorInput, internalComponentName: StringQueryOperatorInput, componentChunkName: StringQueryOperatorInput, matchPath: StringQueryOperatorInput, pageContext: JSONQueryOperatorInput, pluginCreator: SitePluginFilterInput, id: StringQueryOperatorInput, parent: NodeFilterInput, children: NodeFilterListInput, internal: InternalFilterInput): SitePage allSitePage(filter: SitePageFilterInput, sort: SitePageSortInput, skip: Int, limit: Int): SitePageConnection! sitePlugin(resolve: StringQueryOperatorInput, name: StringQueryOperatorInput, version: StringQueryOperatorInput, nodeAPIs: StringQueryOperatorInput, browserAPIs: StringQueryOperatorInput, ssrAPIs: StringQueryOperatorInput, pluginFilepath: StringQueryOperatorInput, pluginOptions: JSONQueryOperatorInput, packageJson: JSONQueryOperatorInput, id: StringQueryOperatorInput, parent: NodeFilterInput, children: NodeFilterListInput, internal: InternalFilterInput): SitePlugin allSitePlugin(filter: SitePluginFilterInput, sort: SitePluginSortInput, skip: Int, limit: Int): SitePluginConnection! @@ -1265,6 +1266,22 @@ input JSONQueryOperatorInput { glob: JSON } +input SitePluginFilterInput { + resolve: StringQueryOperatorInput + name: StringQueryOperatorInput + version: StringQueryOperatorInput + nodeAPIs: StringQueryOperatorInput + browserAPIs: StringQueryOperatorInput + ssrAPIs: StringQueryOperatorInput + pluginFilepath: StringQueryOperatorInput + pluginOptions: JSONQueryOperatorInput + packageJson: JSONQueryOperatorInput + id: StringQueryOperatorInput + parent: NodeFilterInput + children: NodeFilterListInput + internal: InternalFilterInput +} + type SitePageConnection { totalCount: Int! edges: [SitePageEdge!]! @@ -1290,6 +1307,53 @@ enum SitePageFieldsEnum { componentChunkName matchPath pageContext + pluginCreator___resolve + pluginCreator___name + pluginCreator___version + pluginCreator___nodeAPIs + pluginCreator___browserAPIs + pluginCreator___ssrAPIs + pluginCreator___pluginFilepath + pluginCreator___pluginOptions + pluginCreator___packageJson + pluginCreator___id + pluginCreator___parent___id + pluginCreator___parent___parent___id + pluginCreator___parent___parent___children + pluginCreator___parent___children + pluginCreator___parent___children___id + pluginCreator___parent___children___children + pluginCreator___parent___internal___content + pluginCreator___parent___internal___contentDigest + pluginCreator___parent___internal___description + pluginCreator___parent___internal___fieldOwners + pluginCreator___parent___internal___ignoreType + pluginCreator___parent___internal___mediaType + pluginCreator___parent___internal___owner + pluginCreator___parent___internal___type + pluginCreator___children + pluginCreator___children___id + pluginCreator___children___parent___id + pluginCreator___children___parent___children + pluginCreator___children___children + pluginCreator___children___children___id + pluginCreator___children___children___children + pluginCreator___children___internal___content + pluginCreator___children___internal___contentDigest + pluginCreator___children___internal___description + pluginCreator___children___internal___fieldOwners + pluginCreator___children___internal___ignoreType + pluginCreator___children___internal___mediaType + pluginCreator___children___internal___owner + pluginCreator___children___internal___type + pluginCreator___internal___content + pluginCreator___internal___contentDigest + pluginCreator___internal___description + pluginCreator___internal___fieldOwners + pluginCreator___internal___ignoreType + pluginCreator___internal___mediaType + pluginCreator___internal___owner + pluginCreator___internal___type id parent___id parent___parent___id @@ -1399,6 +1463,7 @@ input SitePageFilterInput { componentChunkName: StringQueryOperatorInput matchPath: StringQueryOperatorInput pageContext: JSONQueryOperatorInput + pluginCreator: SitePluginFilterInput id: StringQueryOperatorInput parent: NodeFilterInput children: NodeFilterListInput @@ -1540,22 +1605,6 @@ type SitePluginGroupConnection { fieldValue: String } -input SitePluginFilterInput { - resolve: StringQueryOperatorInput - name: StringQueryOperatorInput - version: StringQueryOperatorInput - nodeAPIs: StringQueryOperatorInput - browserAPIs: StringQueryOperatorInput - ssrAPIs: StringQueryOperatorInput - pluginFilepath: StringQueryOperatorInput - pluginOptions: JSONQueryOperatorInput - packageJson: JSONQueryOperatorInput - id: StringQueryOperatorInput - parent: NodeFilterInput - children: NodeFilterListInput - internal: InternalFilterInput -} - input SitePluginSortInput { fields: [SitePluginFieldsEnum] order: [SortOrderEnum] = [ASC] diff --git a/packages/gatsby/src/schema/__tests__/__snapshots__/print.js.snap b/packages/gatsby/src/schema/__tests__/__snapshots__/print.js.snap index e45db78178ba4..7887a79ceb072 100644 --- a/packages/gatsby/src/schema/__tests__/__snapshots__/print.js.snap +++ b/packages/gatsby/src/schema/__tests__/__snapshots__/print.js.snap @@ -107,6 +107,7 @@ type SitePage implements Node @dontInfer { componentChunkName: String! matchPath: String pageContext: JSON + pluginCreator: SitePlugin @link(by: \\"id\\", from: \\"pluginCreatorId\\") } type SitePlugin implements Node @dontInfer { @@ -288,6 +289,7 @@ type SitePage implements Node @dontInfer { componentChunkName: String! matchPath: String pageContext: JSON + pluginCreator: SitePlugin @link(by: \\"id\\", from: \\"pluginCreatorId\\") } type SitePlugin implements Node @dontInfer { @@ -480,6 +482,7 @@ type SitePage implements Node @dontInfer { componentChunkName: String! matchPath: String pageContext: JSON + pluginCreator: SitePlugin @link(by: \\"id\\", from: \\"pluginCreatorId\\") } type SitePlugin implements Node @dontInfer { 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 44de6f0cb4c7b..4eaabad246f4a 100644 --- a/packages/gatsby/src/schema/__tests__/__snapshots__/rebuild-schema.js.snap +++ b/packages/gatsby/src/schema/__tests__/__snapshots__/rebuild-schema.js.snap @@ -422,6 +422,7 @@ type SitePage implements Node { componentChunkName: String! matchPath: String pageContext: JSON + pluginCreator: SitePlugin id: ID! parent: Node children: [Node!]! @@ -482,7 +483,7 @@ type Query { allSite(filter: SiteFilterInput, sort: SiteSortInput, skip: Int, limit: Int): SiteConnection! siteFunction(functionRoute: StringQueryOperatorInput, pluginName: StringQueryOperatorInput, originalAbsoluteFilePath: StringQueryOperatorInput, originalRelativeFilePath: StringQueryOperatorInput, relativeCompiledFilePath: StringQueryOperatorInput, absoluteCompiledFilePath: StringQueryOperatorInput, matchPath: StringQueryOperatorInput, id: StringQueryOperatorInput, parent: NodeFilterInput, children: NodeFilterListInput, internal: InternalFilterInput): SiteFunction allSiteFunction(filter: SiteFunctionFilterInput, sort: SiteFunctionSortInput, skip: Int, limit: Int): SiteFunctionConnection! - sitePage(path: StringQueryOperatorInput, component: StringQueryOperatorInput, internalComponentName: StringQueryOperatorInput, componentChunkName: StringQueryOperatorInput, matchPath: StringQueryOperatorInput, pageContext: JSONQueryOperatorInput, id: StringQueryOperatorInput, parent: NodeFilterInput, children: NodeFilterListInput, internal: InternalFilterInput): SitePage + sitePage(path: StringQueryOperatorInput, component: StringQueryOperatorInput, internalComponentName: StringQueryOperatorInput, componentChunkName: StringQueryOperatorInput, matchPath: StringQueryOperatorInput, pageContext: JSONQueryOperatorInput, pluginCreator: SitePluginFilterInput, id: StringQueryOperatorInput, parent: NodeFilterInput, children: NodeFilterListInput, internal: InternalFilterInput): SitePage allSitePage(filter: SitePageFilterInput, sort: SitePageSortInput, skip: Int, limit: Int): SitePageConnection! sitePlugin(resolve: StringQueryOperatorInput, name: StringQueryOperatorInput, version: StringQueryOperatorInput, nodeAPIs: StringQueryOperatorInput, browserAPIs: StringQueryOperatorInput, ssrAPIs: StringQueryOperatorInput, pluginFilepath: StringQueryOperatorInput, pluginOptions: JSONQueryOperatorInput, packageJson: JSONQueryOperatorInput, id: StringQueryOperatorInput, parent: NodeFilterInput, children: NodeFilterListInput, internal: InternalFilterInput): SitePlugin allSitePlugin(filter: SitePluginFilterInput, sort: SitePluginSortInput, skip: Int, limit: Int): SitePluginConnection! @@ -1265,6 +1266,22 @@ input JSONQueryOperatorInput { glob: JSON } +input SitePluginFilterInput { + resolve: StringQueryOperatorInput + name: StringQueryOperatorInput + version: StringQueryOperatorInput + nodeAPIs: StringQueryOperatorInput + browserAPIs: StringQueryOperatorInput + ssrAPIs: StringQueryOperatorInput + pluginFilepath: StringQueryOperatorInput + pluginOptions: JSONQueryOperatorInput + packageJson: JSONQueryOperatorInput + id: StringQueryOperatorInput + parent: NodeFilterInput + children: NodeFilterListInput + internal: InternalFilterInput +} + type SitePageConnection { totalCount: Int! edges: [SitePageEdge!]! @@ -1290,6 +1307,53 @@ enum SitePageFieldsEnum { componentChunkName matchPath pageContext + pluginCreator___resolve + pluginCreator___name + pluginCreator___version + pluginCreator___nodeAPIs + pluginCreator___browserAPIs + pluginCreator___ssrAPIs + pluginCreator___pluginFilepath + pluginCreator___pluginOptions + pluginCreator___packageJson + pluginCreator___id + pluginCreator___parent___id + pluginCreator___parent___parent___id + pluginCreator___parent___parent___children + pluginCreator___parent___children + pluginCreator___parent___children___id + pluginCreator___parent___children___children + pluginCreator___parent___internal___content + pluginCreator___parent___internal___contentDigest + pluginCreator___parent___internal___description + pluginCreator___parent___internal___fieldOwners + pluginCreator___parent___internal___ignoreType + pluginCreator___parent___internal___mediaType + pluginCreator___parent___internal___owner + pluginCreator___parent___internal___type + pluginCreator___children + pluginCreator___children___id + pluginCreator___children___parent___id + pluginCreator___children___parent___children + pluginCreator___children___children + pluginCreator___children___children___id + pluginCreator___children___children___children + pluginCreator___children___internal___content + pluginCreator___children___internal___contentDigest + pluginCreator___children___internal___description + pluginCreator___children___internal___fieldOwners + pluginCreator___children___internal___ignoreType + pluginCreator___children___internal___mediaType + pluginCreator___children___internal___owner + pluginCreator___children___internal___type + pluginCreator___internal___content + pluginCreator___internal___contentDigest + pluginCreator___internal___description + pluginCreator___internal___fieldOwners + pluginCreator___internal___ignoreType + pluginCreator___internal___mediaType + pluginCreator___internal___owner + pluginCreator___internal___type id parent___id parent___parent___id @@ -1399,6 +1463,7 @@ input SitePageFilterInput { componentChunkName: StringQueryOperatorInput matchPath: StringQueryOperatorInput pageContext: JSONQueryOperatorInput + pluginCreator: SitePluginFilterInput id: StringQueryOperatorInput parent: NodeFilterInput children: NodeFilterListInput @@ -1540,22 +1605,6 @@ type SitePluginGroupConnection { fieldValue: String } -input SitePluginFilterInput { - resolve: StringQueryOperatorInput - name: StringQueryOperatorInput - version: StringQueryOperatorInput - nodeAPIs: StringQueryOperatorInput - browserAPIs: StringQueryOperatorInput - ssrAPIs: StringQueryOperatorInput - pluginFilepath: StringQueryOperatorInput - pluginOptions: JSONQueryOperatorInput - packageJson: JSONQueryOperatorInput - id: StringQueryOperatorInput - parent: NodeFilterInput - children: NodeFilterListInput - internal: InternalFilterInput -} - input SitePluginSortInput { fields: [SitePluginFieldsEnum] order: [SortOrderEnum] = [ASC] diff --git a/packages/gatsby/src/schema/__tests__/build-schema.js b/packages/gatsby/src/schema/__tests__/build-schema.js index fbdf3d727cdfc..757a5d7a5e74f 100644 --- a/packages/gatsby/src/schema/__tests__/build-schema.js +++ b/packages/gatsby/src/schema/__tests__/build-schema.js @@ -1117,6 +1117,7 @@ describe(`Build schema`, () => { `componentChunkName`, `matchPath`, `pageContext`, + `pluginCreator`, `bar`, `id`, `parent`, @@ -1156,6 +1157,7 @@ describe(`Build schema`, () => { `componentChunkName`, `matchPath`, `pageContext`, + `pluginCreator`, `bar`, `id`, `parent`, diff --git a/packages/gatsby/src/schema/__tests__/rebuild-schema.js b/packages/gatsby/src/schema/__tests__/rebuild-schema.js index b0847ec3afb9f..cee216f71c20e 100644 --- a/packages/gatsby/src/schema/__tests__/rebuild-schema.js +++ b/packages/gatsby/src/schema/__tests__/rebuild-schema.js @@ -10,7 +10,7 @@ const { } = require(`graphql`) const { store } = require(`../../redux`) const { actions } = require(`../../redux/actions`) -const { build, rebuild, rebuildWithSitePage } = require(`..`) +const { build, rebuild } = require(`..`) import { buildObjectType } from "../types/type-builders" jest.mock(`../../utils/api-runner-node`) @@ -60,7 +60,6 @@ const addNodeField = ({ node, name, value }) => { const rebuildTestSchema = async () => { await rebuild({}) - await rebuildWithSitePage({}) return store.getState().schema } @@ -1178,7 +1177,6 @@ describe(`Compatibility with addThirdPartySchema`, () => { }) createNodes().forEach(addNode) await build({}) - await rebuildWithSitePage({}) const schema = store.getState().schema assertValidSchema(schema) }) diff --git a/packages/gatsby/src/schema/__tests__/rebuild-sitepage-type.js b/packages/gatsby/src/schema/__tests__/rebuild-sitepage-type.js deleted file mode 100644 index 603755ee44f0b..0000000000000 --- a/packages/gatsby/src/schema/__tests__/rebuild-sitepage-type.js +++ /dev/null @@ -1,216 +0,0 @@ -const { store } = require(`../../redux`) -const { graphql } = require(`../../../graphql`) -const { build, rebuildWithSitePage } = require(`..`) - -jest.mock(`gatsby-cli/lib/reporter`, () => { - return { - log: jest.fn(), - info: jest.fn(), - warn: jest.fn(), - error: jest.fn(), - activityTimer: () => { - return { - start: jest.fn(), - setStatus: jest.fn(), - end: jest.fn(), - } - }, - phantomActivity: () => { - return { - start: jest.fn(), - end: jest.fn(), - } - }, - } -}) - -const firstPage = () => { - return { - id: `page1`, - parent: null, - children: [], - internal: { type: `SitePage`, contentDigest: `0`, counter: 0 }, - keep: `Page`, - fields: { - oldKey: `value`, - }, - } -} - -const secondPage = () => { - return { - id: `page2`, - parent: null, - children: [], - internal: { type: `SitePage`, contentDigest: `0`, counter: 1 }, - fields: { - key: `value`, - }, - context: { - key: `value`, - }, - } -} - -const nodes = () => [firstPage()] - -describe(`build and update schema for SitePage`, () => { - let schema - - beforeEach(async () => { - store.dispatch({ type: `DELETE_CACHE` }) - nodes().forEach(node => - store.dispatch({ type: `CREATE_NODE`, payload: node }) - ) - - await build({}) - schema = store.getState().schema - }) - - it(`updates SitePage on rebuild`, async () => { - let fields - let inputFields - - const initialFields = [ - `path`, - `component`, - `internalComponentName`, - `componentChunkName`, - `matchPath`, - `pageContext`, - `keep`, - `fields`, - `id`, - `parent`, - `children`, - `internal`, - ] - - fields = Object.keys(schema.getType(`SitePage`).getFields()) - expect(fields.length).toBe(12) - expect(fields).toEqual(initialFields) - - inputFields = Object.keys(schema.getType(`SitePageFilterInput`).getFields()) - expect(fields.length).toBe(12) - expect(inputFields).toEqual(initialFields) - - // Rebuild Schema - store.dispatch({ type: `CREATE_NODE`, payload: secondPage() }) - await rebuildWithSitePage({}) - schema = store.getState().schema - - fields = Object.keys(schema.getType(`SitePage`).getFields()) - expect(fields.length).toBe(13) - expect(fields.sort()).toEqual(initialFields.concat(`context`).sort()) - - inputFields = Object.keys(schema.getType(`SitePageFilterInput`).getFields()) - expect(fields.length).toBe(13) - expect(inputFields.sort()).toEqual(initialFields.concat(`context`).sort()) - - const fieldsEnum = schema - .getType(`SitePageFieldsEnum`) - .getValue(`context___key`) - expect(fieldsEnum).toBeDefined() - - const sortFieldsEnum = schema.getType(`SitePageSortInput`).getFields() - .fields.type.ofType - expect(sortFieldsEnum.getValue(`context___key`)).toBeDefined() - }) - - const testNestedFields = async () => { - let fields - let inputFields - - fields = Object.keys(schema.getType(`SitePageFields`).getFields()) - expect(fields.length).toBe(1) - expect(fields).toEqual([`oldKey`]) - inputFields = Object.keys( - schema.getType(`SitePageFieldsFilterInput`).getFields() - ) - expect(inputFields.length).toBe(1) - expect(inputFields).toEqual([`oldKey`]) - - // Rebuild Schema - store.dispatch({ type: `CREATE_NODE`, payload: secondPage() }) - await rebuildWithSitePage({}) - schema = store.getState().schema - - fields = Object.keys(schema.getType(`SitePageFields`).getFields()) - expect(fields.length).toBe(2) - expect(fields).toEqual([`oldKey`, `key`]) - - inputFields = Object.keys( - schema.getType(`SitePageFieldsFilterInput`).getFields() - ) - expect(inputFields.length).toBe(2) - expect(inputFields).toEqual([`oldKey`, `key`]) - - const fieldsEnum = schema - .getType(`SitePageFieldsEnum`) - .getValues() - .map(value => value.name) - expect(fieldsEnum.includes(`fields___oldKey`)).toBeTruthy() - expect(fieldsEnum.includes(`fields___key`)).toBeTruthy() - } - - it(`updates nested types on rebuild`, testNestedFields) - - it(`updates nested types on rebuild (with query executed before rebuilding)`, async () => { - // Set a stage for the same test as above but with graphql query executed before updating schema - // See https://github.com/gatsbyjs/gatsby/issues/30107 - const result = await graphql( - schema, - ` - { - __typename - } - `, - null, - {} - ) - expect(result).toEqual({ data: { __typename: `Query` } }) - await testNestedFields() - }) - - it(`updates nested input types on rebuild`, async () => { - // sanity-check - const inputFields = Object.keys( - schema.getType(`SitePageFieldsFilterInput`).getFields() - ) - expect(inputFields.length).toBe(1) - expect(inputFields).toEqual([`oldKey`]) - - // Rebuild - const page = firstPage() - page.fields = {} - store.dispatch({ type: `CREATE_NODE`, payload: page }) - await rebuildWithSitePage({}) - schema = store.getState().schema - - expect(schema.getType(`SitePageFieldsFilterInput`)).toBeUndefined() - }) - - it(`respects @dontInfer on SitePage`, async () => { - const typeDefs = ` - type SitePage implements Node @dontInfer { - keep: String! - fields: SitePageFields - } - type SitePageFields { - temp: String! - } - ` - store.dispatch({ type: `CREATE_TYPES`, payload: typeDefs }) - - // rebuildWithSitePage ignores new type definitions, - // so need to build again first - await build({}) - - store.dispatch({ type: `CREATE_NODE`, payload: secondPage() }) - - await rebuildWithSitePage({}) - schema = store.getState().schema - expect(schema.getType(`SitePage`).getFields().context).not.toBeDefined() - expect(schema.getType(`SitePageFields`).getFields().key).not.toBeDefined() - }) -}) diff --git a/packages/gatsby/src/schema/graphql-engine/entry.ts b/packages/gatsby/src/schema/graphql-engine/entry.ts index 093ac819e26c7..875b58874e226 100644 --- a/packages/gatsby/src/schema/graphql-engine/entry.ts +++ b/packages/gatsby/src/schema/graphql-engine/entry.ts @@ -66,7 +66,7 @@ export class GraphQLEngine { // Build runs // Note: skipping inference metadata because we rely on schema snapshot - await build({ fullMetadataBuild: false, freeze: true }) + await build({ fullMetadataBuild: false }) return createGraphQLRunner(store, reporter) } diff --git a/packages/gatsby/src/schema/index.js b/packages/gatsby/src/schema/index.js index fabedb9cab763..80b18c68e2f7a 100644 --- a/packages/gatsby/src/schema/index.js +++ b/packages/gatsby/src/schema/index.js @@ -4,7 +4,7 @@ const tracer = require(`opentracing`).globalTracer() const { store } = require(`../redux`) const { getDataStore, getTypes } = require(`../datastore`) const { createSchemaComposer } = require(`./schema-composer`) -const { buildSchema, rebuildSchemaWithSitePage } = require(`./schema`) +const { buildSchema } = require(`./schema`) const { builtInFieldExtensions } = require(`./extensions`) const { builtInTypeDefinitions } = require(`./types/built-in-types`) const { TypeConflictReporter } = require(`./infer/type-conflict-reporter`) @@ -79,23 +79,15 @@ const buildInferenceMetadata = ({ types }) => processNextType() }) -const build = async ({ - parentSpan, - fullMetadataBuild = true, - freeze = false, -}) => { +const build = async ({ parentSpan, fullMetadataBuild = true }) => { const spanArgs = parentSpan ? { childOf: parentSpan } : {} const span = tracer.startSpan(`build schema`, spanArgs) await getDataStore().ready() if (fullMetadataBuild) { // Build metadata for type inference and start updating it incrementally - // except for SitePage type: we rebuild it in rebuildWithSitePage anyway - // so it makes little sense to update it incrementally - // (and those updates may have significant performance overhead) await buildInferenceMetadata({ types: getTypes() }) store.dispatch({ type: `START_INCREMENTAL_INFERENCE` }) - store.dispatch({ type: `DISABLE_TYPE_INFERENCE`, payload: [`SitePage`] }) } const { @@ -127,7 +119,6 @@ const build = async ({ enginePrintConfig, typeConflictReporter, inferenceMetadata, - freeze, parentSpan, }) @@ -148,54 +139,7 @@ const build = async ({ const rebuild = async ({ parentSpan }) => await build({ parentSpan, fullMetadataBuild: false }) -const rebuildWithSitePage = async ({ parentSpan }) => { - const spanArgs = parentSpan ? { childOf: parentSpan } : {} - const span = tracer.startSpan( - `rebuild schema with SitePage context`, - spanArgs - ) - await getDataStore().ready() - await buildInferenceMetadata({ types: [`SitePage`] }) - - // Disabling incremental inference for SitePage after the initial build - // as it has a significant performance cost for zero benefits. - // The only benefit is that schema rebuilds when SitePage.context structure changes. - // (one can just restart `develop` in this case) - store.dispatch({ type: `DISABLE_TYPE_INFERENCE`, payload: [`SitePage`] }) - - const { - schemaCustomization: { composer: schemaComposer }, - config: { mapping: typeMapping }, - inferenceMetadata, - } = store.getState() - - const typeConflictReporter = new TypeConflictReporter() - - const schema = await rebuildSchemaWithSitePage({ - schemaComposer, - fieldExtensions: getAllFieldExtensions(), - typeMapping, - typeConflictReporter, - inferenceMetadata, - parentSpan, - }) - - typeConflictReporter.printConflicts() - - store.dispatch({ - type: `SET_SCHEMA_COMPOSER`, - payload: schemaComposer, - }) - store.dispatch({ - type: `SET_SCHEMA`, - payload: schema, - }) - - span.finish() -} - module.exports = { build, rebuild, - rebuildWithSitePage, } diff --git a/packages/gatsby/src/schema/schema.js b/packages/gatsby/src/schema/schema.js index dcdef53137742..e9f8f65326fde 100644 --- a/packages/gatsby/src/schema/schema.js +++ b/packages/gatsby/src/schema/schema.js @@ -24,7 +24,7 @@ const apiRunner = require(`../utils/api-runner-node`) const report = require(`gatsby-cli/lib/reporter`) const { addNodeInterfaceFields } = require(`./types/node-interface`) const { overridableBuiltInTypeNames } = require(`./types/built-in-types`) -const { addInferredType, addInferredTypes } = require(`./infer`) +const { addInferredTypes } = require(`./infer`) const { findOne, findManyPaginated, @@ -45,10 +45,6 @@ const { parseTypeDef, reportParsingError, } = require(`./types/type-defs`) -import { - clearDerivedTypes, - deleteFieldsOfDerivedTypes, -} from "./types/derived-types" const { printTypeDefinitions } = require(`./print`) const buildSchema = async ({ @@ -61,7 +57,6 @@ const buildSchema = async ({ enginePrintConfig, typeConflictReporter, inferenceMetadata, - freeze = false, parentSpan, }) => { // FIXME: consider removing .ready here - it is needed for various tests to pass (although probably harmless) @@ -80,59 +75,14 @@ const buildSchema = async ({ }) // const { printSchema } = require(`graphql`) const schema = schemaComposer.buildSchema() - - if (freeze) { - freezeTypeComposers(schemaComposer) - } - - // console.log(printSchema(schema)) - return schema -} - -const rebuildSchemaWithSitePage = async ({ - schemaComposer, - typeMapping, - fieldExtensions, - typeConflictReporter, - inferenceMetadata, - parentSpan, -}) => { - const typeComposer = schemaComposer.getOTC(`SitePage`) - - // Clear derived types and fields - // they will be re-created in processTypeComposer later - deleteFieldsOfDerivedTypes({ typeComposer }) - clearDerivedTypes({ schemaComposer, typeComposer }) - - const shouldInfer = - !typeComposer.hasExtension(`infer`) || - typeComposer.getExtension(`infer`) !== false - if (shouldInfer) { - addInferredType({ - schemaComposer, - typeComposer, - typeConflictReporter, - typeMapping, - inferenceMetadata, - parentSpan, - }) - } - await processTypeComposer({ - schemaComposer, - typeComposer, - fieldExtensions, - parentSpan, - }) - const schema = schemaComposer.buildSchema() - freezeTypeComposers(schemaComposer) + // console.log(printSchema(schema)) return schema } module.exports = { buildSchema, - rebuildSchemaWithSitePage, } // Workaround for https://github.com/graphql-compose/graphql-compose/issues/319 diff --git a/packages/gatsby/src/schema/types/built-in-types.ts b/packages/gatsby/src/schema/types/built-in-types.ts index 1a32429e9afd1..647dc20e1250c 100644 --- a/packages/gatsby/src/schema/types/built-in-types.ts +++ b/packages/gatsby/src/schema/types/built-in-types.ts @@ -101,13 +101,14 @@ const siteSiteMetadataType = ` ` const sitePageType = ` - type SitePage implements Node @infer { + type SitePage implements Node @dontInfer { path: String! component: String! internalComponentName: String! componentChunkName: String! matchPath: String pageContext: JSON + pluginCreator: SitePlugin @link(from: "pluginCreatorId") } ` diff --git a/packages/gatsby/src/services/index.ts b/packages/gatsby/src/services/index.ts index a7581f220ccb9..7fe50baf03938 100644 --- a/packages/gatsby/src/services/index.ts +++ b/packages/gatsby/src/services/index.ts @@ -1,5 +1,4 @@ export { startWebpackServer } from "./start-webpack-server" -export { rebuildSchemaWithSitePage } from "./rebuild-schema-with-site-pages" export { extractQueries } from "./extract-queries" export { writeOutRedirects } from "./write-out-redirects" export { postBootstrap } from "./post-bootstrap" diff --git a/packages/gatsby/src/services/rebuild-schema-with-site-pages.ts b/packages/gatsby/src/services/rebuild-schema-with-site-pages.ts deleted file mode 100644 index 6ac23b057725b..0000000000000 --- a/packages/gatsby/src/services/rebuild-schema-with-site-pages.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { rebuildWithSitePage } from "../schema" -import reporter from "gatsby-cli/lib/reporter" -import { IQueryRunningContext } from "../state-machines/query-running/types" - -export async function rebuildSchemaWithSitePage({ - parentSpan, -}: Partial): Promise { - const activity = reporter.activityTimer(`update schema`, { - parentSpan, - }) - activity.start() - await rebuildWithSitePage({ parentSpan }) - activity.end() -} diff --git a/packages/gatsby/src/state-machines/data-layer/index.ts b/packages/gatsby/src/state-machines/data-layer/index.ts index 7d1f9f9929475..25c5f146f6d2a 100644 --- a/packages/gatsby/src/state-machines/data-layer/index.ts +++ b/packages/gatsby/src/state-machines/data-layer/index.ts @@ -48,17 +48,9 @@ const initialCreatePagesStates: StatesConfig = { invoke: { id: `creating-pages`, src: `createPages`, - onDone: { - target: `rebuildingSchemaWithSitePage`, - actions: `assignChangedPages`, - }, - }, - }, - rebuildingSchemaWithSitePage: { - invoke: { - src: `rebuildSchemaWithSitePage`, onDone: { target: `writingOutRedirects`, + actions: `assignChangedPages`, }, }, }, @@ -87,17 +79,9 @@ const recreatePagesStates: StatesConfig = { invoke: { id: `creating-pages`, src: `createPages`, - onDone: { - target: `rebuildingSchemaWithSitePage`, - actions: `assignChangedPages`, - }, - }, - }, - rebuildingSchemaWithSitePage: { - invoke: { - src: `rebuildSchemaWithSitePage`, onDone: { target: `done`, + actions: `assignChangedPages`, }, }, }, diff --git a/packages/gatsby/src/state-machines/data-layer/services.ts b/packages/gatsby/src/state-machines/data-layer/services.ts index a32125abbbc33..3dd8e34ebf8b5 100644 --- a/packages/gatsby/src/state-machines/data-layer/services.ts +++ b/packages/gatsby/src/state-machines/data-layer/services.ts @@ -4,7 +4,6 @@ import { createPages, buildSchema, sourceNodes, - rebuildSchemaWithSitePage, writeOutRedirects as writeOutRedirectsAndWatch, } from "../../services" import { IDataLayerContext } from "./types" @@ -17,6 +16,5 @@ export const dataLayerServices: Record< sourceNodes, createPages, buildSchema, - rebuildSchemaWithSitePage, writeOutRedirectsAndWatch, } diff --git a/packages/gatsby/src/state-machines/query-running/services.ts b/packages/gatsby/src/state-machines/query-running/services.ts index e5b7aaa1b2794..499e6898aa143 100644 --- a/packages/gatsby/src/state-machines/query-running/services.ts +++ b/packages/gatsby/src/state-machines/query-running/services.ts @@ -7,7 +7,6 @@ import { runPageQueries, waitUntilAllJobsComplete, writeOutRedirects, - rebuildSchemaWithSitePage, } from "../../services" import { IQueryRunningContext } from "./types" @@ -22,5 +21,4 @@ export const queryRunningServices: Record< runPageQueries, waitUntilAllJobsComplete, writeOutRedirects, - rebuildSchemaWithSitePage, } diff --git a/packages/gatsby/src/utils/worker/child/schema.ts b/packages/gatsby/src/utils/worker/child/schema.ts index 57e5921e94d4d..0f4dea90220c9 100644 --- a/packages/gatsby/src/utils/worker/child/schema.ts +++ b/packages/gatsby/src/utils/worker/child/schema.ts @@ -22,5 +22,5 @@ export async function buildSchema(): Promise { await apiRunnerNode(`createSchemaCustomization`) // build() runs other lifecycles like "createResolvers" or "setFieldsOnGraphQLNodeType" internally - await build({ fullMetadataBuild: false, freeze: true, parentSpan: {} }) + await build({ fullMetadataBuild: false, parentSpan: {} }) }