Skip to content

Commit

Permalink
chore(gatsby): migrate schema reducer to TypeScript (#23591)
Browse files Browse the repository at this point in the history
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.

Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
  • Loading branch information
hiwelo and pieh authored May 5, 2020
1 parent 9970faf commit a694d43
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/gatsby/src/redux/reducers/index.js
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -59,7 +60,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`),
Expand Down
8 changes: 0 additions & 8 deletions packages/gatsby/src/redux/reducers/schema.js

This file was deleted.

14 changes: 14 additions & 0 deletions packages/gatsby/src/redux/reducers/schema.ts
Original file line number Diff line number Diff line change
@@ -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
}
}
6 changes: 6 additions & 0 deletions packages/gatsby/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export type ActionsUnion =
| IReplaceWebpackConfigAction
| ISetPluginStatusAction
| ISetProgramStatusAction
| ISetSchemaAction
| ISetWebpackCompilationHashAction
| ISetWebpackConfigAction
| IUpdatePluginsHashAction
Expand Down Expand Up @@ -448,6 +449,11 @@ export interface ISetWebpackConfigAction {
payload: Partial<IGatsbyState["webpack"]>
}

export interface ISetSchemaAction {
type: `SET_SCHEMA`
payload: IGatsbyState["schema"]
}

export interface ISetSiteConfig {
type: `SET_SITE_CONFIG`
payload: IGatsbyState["config"]
Expand Down

0 comments on commit a694d43

Please sign in to comment.