Skip to content

Commit

Permalink
feat(gatsby): Deprecate schema-related APIs in sourceNodes (#32291)
Browse files Browse the repository at this point in the history
* 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 <lekoarts@gmail.com>
Co-authored-by: Ward Peeters <ward@coding-tech.com>
Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
  • Loading branch information
4 people committed Sep 10, 2021
1 parent 62683f5 commit 3401149
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
9 changes: 7 additions & 2 deletions packages/gatsby/src/redux/actions/__tests__/restricted.js
Expand Up @@ -14,20 +14,25 @@ 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()
expect(report.error).not.toHaveBeenCalled()
})

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`, () => {
Expand Down
11 changes: 6 additions & 5 deletions packages/gatsby/src/redux/actions/restricted.ts
Expand Up @@ -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`],
Expand Down

0 comments on commit 3401149

Please sign in to comment.