diff --git a/packages/gatsby/src/redux/reducers/index.js b/packages/gatsby/src/redux/reducers/index.js index 99eb602d82163..1ebc8aa22e705 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 { staticQueryComponentsReducer } from "./static-query-components" import { reducer as logReducer } from "gatsby-cli/lib/reporter/redux/reducer" const backend = process.env.GATSBY_DB_NODES || `redux` @@ -56,7 +57,7 @@ module.exports = { status: require(`./status`), componentDataDependencies: require(`./component-data-dependencies`), components: require(`./components`), - staticQueryComponents: require(`./static-query-components`), + staticQueryComponents: staticQueryComponentsReducer, jobs: require(`./jobs`), jobsV2: require(`./jobsv2`), webpack: require(`./webpack`), diff --git a/packages/gatsby/src/redux/reducers/static-query-components.js b/packages/gatsby/src/redux/reducers/static-query-components.ts similarity index 54% rename from packages/gatsby/src/redux/reducers/static-query-components.js rename to packages/gatsby/src/redux/reducers/static-query-components.ts index b6cbac29c9b85..5044353e9705c 100644 --- a/packages/gatsby/src/redux/reducers/static-query-components.js +++ b/packages/gatsby/src/redux/reducers/static-query-components.ts @@ -1,4 +1,9 @@ -module.exports = (state = new Map(), action) => { +import { ActionsUnion, IGatsbyState } from "../types" + +export const staticQueryComponentsReducer = ( + state: IGatsbyState["staticQueryComponents"] = new Map(), + action: ActionsUnion +): IGatsbyState["staticQueryComponents"] => { switch (action.type) { case `DELETE_CACHE`: return new Map() diff --git a/packages/gatsby/src/redux/types.ts b/packages/gatsby/src/redux/types.ts index 56233025ee1d1..c59bd93f816f2 100644 --- a/packages/gatsby/src/redux/types.ts +++ b/packages/gatsby/src/redux/types.ts @@ -81,6 +81,14 @@ export interface IGatsbyPluginContext { [key: string]: (...args: any[]) => any } +export interface IGatsbyStaticQueryComponents { + name: string + componentPath: SystemPath + id: Identifier + query: string + hash: string +} + type GatsbyNodes = Map export interface IGatsbyState { @@ -139,14 +147,8 @@ export interface IGatsbyState { } > staticQueryComponents: Map< - number, - { - name: string - componentPath: SystemPath - id: Identifier - query: string - hash: string - } + IGatsbyStaticQueryComponents["id"], + IGatsbyStaticQueryComponents > // @deprecated jobs: { @@ -207,6 +209,7 @@ export interface ICachedReduxState { export type ActionsUnion = | ICreatePageDependencyAction + | IDeleteCacheAction | IDeleteComponentDependenciesAction | IReplaceComponentQueryAction | IReplaceStaticQueryAction @@ -220,6 +223,7 @@ export type ActionsUnion = | ICreateTypes | ICreateFieldExtension | IPrintTypeDefinitions + | IRemoveStaticQuery export interface ICreatePageDependencyAction { type: `CREATE_COMPONENT_DEPENDENCY` @@ -359,3 +363,17 @@ export interface ICreateRedirectAction { type: `CREATE_REDIRECT` payload: IRedirect } + +export interface IDeleteCacheAction { + type: `DELETE_CACHE` +} + +export interface IReplaceStaticQueryAction { + type: `REPLACE_STATIC_QUERY` + payload: IGatsbyStaticQueryComponents +} + +export interface IRemoveStaticQuery { + type: `REMOVE_STATIC_QUERY` + payload: IGatsbyStaticQueryComponents["id"] +}