From 340114956af1be28678f8b0cf760392e202aea69 Mon Sep 17 00:00:00 2001 From: Abhi Aiyer Date: Fri, 10 Sep 2021 08:47:59 -0500 Subject: [PATCH] feat(gatsby): Deprecate schema-related APIs in sourceNodes (#32291) * Deprecate createTypes in sourceNodes * Update the restriction list for other schema-related actions * Update snapshots * Restore package.test.js.snap * Restore share-state.ts Co-authored-by: Lennart Co-authored-by: Ward Peeters Co-authored-by: gatsbybot --- .../gatsby/src/redux/actions/__tests__/restricted.js | 9 +++++++-- packages/gatsby/src/redux/actions/restricted.ts | 11 ++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/gatsby/src/redux/actions/__tests__/restricted.js b/packages/gatsby/src/redux/actions/__tests__/restricted.js index b4be6ebb6dc19..fff7ccc78c205 100644 --- a/packages/gatsby/src/redux/actions/__tests__/restricted.js +++ b/packages/gatsby/src/redux/actions/__tests__/restricted.js @@ -14,7 +14,7 @@ const dispatchWithThunk = actionOrThunk => describe(`Restricted actions`, () => { it(`handles actions allowed in API`, () => { const action = dispatchWithThunk( - availableActionsByAPI.sourceNodes.createTypes() + availableActionsByAPI.createSchemaCustomization.createTypes() ) expect(action).toEqual({ type: `CREATE_TYPES` }) expect(report.warn).not.toHaveBeenCalled() @@ -22,12 +22,17 @@ describe(`Restricted actions`, () => { }) it(`handles actions deprecated in API`, () => { - const action = dispatchWithThunk( + let action = dispatchWithThunk( availableActionsByAPI.onPreBootstrap.createTypes() ) expect(action).toEqual({ type: `CREATE_TYPES` }) expect(report.warn).toHaveBeenCalled() expect(report.error).not.toHaveBeenCalled() + + action = dispatchWithThunk(availableActionsByAPI.sourceNodes.createTypes()) + expect(action).toEqual({ type: `CREATE_TYPES` }) + expect(report.warn).toHaveBeenCalled() + expect(report.error).not.toHaveBeenCalled() }) it(`handles actions forbidden in API`, () => { diff --git a/packages/gatsby/src/redux/actions/restricted.ts b/packages/gatsby/src/redux/actions/restricted.ts index 533498cd42256..4c01c88586dae 100644 --- a/packages/gatsby/src/redux/actions/restricted.ts +++ b/packages/gatsby/src/redux/actions/restricted.ts @@ -522,18 +522,19 @@ const mapAvailableActionsToAPIs = ( export const availableActionsByAPI = mapAvailableActionsToAPIs({ createFieldExtension: { - [ALLOWED_IN]: [`sourceNodes`, `createSchemaCustomization`], + [ALLOWED_IN]: [`createSchemaCustomization`], + [DEPRECATED_IN]: [`sourceNodes`], }, createTypes: { - [ALLOWED_IN]: [`sourceNodes`, `createSchemaCustomization`], - [DEPRECATED_IN]: [`onPreInit`, `onPreBootstrap`], + [ALLOWED_IN]: [`createSchemaCustomization`], + [DEPRECATED_IN]: [`onPreInit`, `onPreBootstrap`, `sourceNodes`], }, createResolverContext: { [ALLOWED_IN]: [`createSchemaCustomization`], }, addThirdPartySchema: { - [ALLOWED_IN]: [`sourceNodes`, `createSchemaCustomization`], - [DEPRECATED_IN]: [`onPreInit`, `onPreBootstrap`], + [ALLOWED_IN]: [`createSchemaCustomization`], + [DEPRECATED_IN]: [`onPreInit`, `onPreBootstrap`, `sourceNodes`], }, printTypeDefinitions: { [ALLOWED_IN]: [`createSchemaCustomization`],