Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(gatsby): migrate schema reducer to TypeScript #23476

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { webpackCompilationHashReducer } from "./webpack-compilation-hash"
Expand Down Expand Up @@ -55,7 +56,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.

13 changes: 13 additions & 0 deletions packages/gatsby/src/redux/reducers/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ActionsUnion, IGatsbyState } from "../types"

export const schemaReducer = (
state: IGatsbyState["schema"] | {} = {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite what I was getting at. I think it would better if we could default this state to an instance of graphql schema. There are APIs and keys that are expected to be on this state. It's fragile to not have them there, even though we must be supporting that as is right now.

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 @@ -225,6 +225,7 @@ export type ActionsUnion =
| IReplaceStaticQueryAction
| ISetPluginStatusAction
| ISetProgramStatusAction
| ISetSchemaAction
| ISetWebpackCompilationHashAction
| IUpdatePluginsHashAction

Expand Down Expand Up @@ -399,3 +400,8 @@ export interface ISetPluginStatusAction {
[key: string]: any
}
}

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