From 368db0a9a7d32ca9ee0738189881b5164e577f70 Mon Sep 17 00:00:00 2001 From: Damien Senger Date: Sat, 25 Apr 2020 13:51:12 +0200 Subject: [PATCH] chore(gatsby): migrate schema reducer to TypeScript This commit implements the migration of the schema reducer to TypeScript by adding the SET_SCHEMA action to the ActionsUnion and by adding the basic types from the IGatsbyState. --- packages/gatsby/src/redux/reducers/index.js | 3 ++- packages/gatsby/src/redux/reducers/schema.js | 8 -------- packages/gatsby/src/redux/reducers/schema.ts | 14 ++++++++++++++ packages/gatsby/src/redux/types.ts | 6 ++++++ 4 files changed, 22 insertions(+), 9 deletions(-) delete mode 100644 packages/gatsby/src/redux/reducers/schema.js create mode 100644 packages/gatsby/src/redux/reducers/schema.ts diff --git a/packages/gatsby/src/redux/reducers/index.js b/packages/gatsby/src/redux/reducers/index.js index 8e00d7f40980f..421094284e795 100644 --- a/packages/gatsby/src/redux/reducers/index.js +++ b/packages/gatsby/src/redux/reducers/index.js @@ -1,6 +1,7 @@ const reduxNodes = require(`./nodes`) const lokiNodes = require(`../../db/loki/nodes`).reducer import { redirectsReducer } from "./redirects" +import { schemaReducer } from "./schema" import { staticQueryComponentsReducer } from "./static-query-components" import { statusReducer } from "./status" import { webpackReducer } from "./webpack" @@ -56,7 +57,7 @@ module.exports = { flattenedPlugins: require(`./flattened-plugins`), config: require(`./config`), pages: require(`./pages`), - schema: require(`./schema`), + schema: schemaReducer, status: statusReducer, componentDataDependencies: require(`./component-data-dependencies`), components: require(`./components`), diff --git a/packages/gatsby/src/redux/reducers/schema.js b/packages/gatsby/src/redux/reducers/schema.js deleted file mode 100644 index 01fbacb86082e..0000000000000 --- a/packages/gatsby/src/redux/reducers/schema.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = (state = {}, action) => { - switch (action.type) { - case `SET_SCHEMA`: - return action.payload - default: - return state - } -} diff --git a/packages/gatsby/src/redux/reducers/schema.ts b/packages/gatsby/src/redux/reducers/schema.ts new file mode 100644 index 0000000000000..0c9d239746d7d --- /dev/null +++ b/packages/gatsby/src/redux/reducers/schema.ts @@ -0,0 +1,14 @@ +import { ActionsUnion, IGatsbyState } from "../types" +import { GraphQLSchema } from "graphql" + +export const schemaReducer = ( + state: IGatsbyState["schema"] = new GraphQLSchema({ query: null }), + action: ActionsUnion +): IGatsbyState["schema"] => { + switch (action.type) { + case `SET_SCHEMA`: + return action.payload + default: + return state + } +} diff --git a/packages/gatsby/src/redux/types.ts b/packages/gatsby/src/redux/types.ts index 9c7bd02a82fbb..25a06d5a30833 100644 --- a/packages/gatsby/src/redux/types.ts +++ b/packages/gatsby/src/redux/types.ts @@ -226,6 +226,7 @@ export type ActionsUnion = | IReplaceWebpackConfigAction | ISetPluginStatusAction | ISetProgramStatusAction + | ISetSchemaAction | ISetWebpackCompilationHashAction | ISetWebpackConfigAction | IUpdatePluginsHashAction @@ -411,3 +412,8 @@ export interface ISetWebpackConfigAction { type: `SET_WEBPACK_CONFIG` payload: Partial } + +export interface ISetSchemaAction { + type: `SET_SCHEMA` + payload: IGatsbyState["schema"] +}