Skip to content

Commit

Permalink
fix(gatsby): Defer node mutation in more APIs (#26067)
Browse files Browse the repository at this point in the history
  • Loading branch information
ascorbic committed Jul 28, 2020
1 parent 96e5ed4 commit 5e5b413
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/gatsby/src/services/create-pages.ts
Expand Up @@ -9,6 +9,7 @@ export async function createPages({
parentSpan,
gatsbyNodeGraphQLFunction,
store,
deferNodeMutation,
}: Partial<IDataLayerContext>): Promise<{
deletedPages: string[]
changedPages: string[]
Expand All @@ -28,6 +29,7 @@ export async function createPages({
traceId: `initial-createPages`,
waitForCascadingActions: true,
parentSpan: activity.span,
deferNodeMutation,
},
{ activity }
)
Expand Down
2 changes: 2 additions & 0 deletions packages/gatsby/src/services/customize-schema.ts
Expand Up @@ -4,6 +4,7 @@ import { IDataLayerContext } from "../state-machines/data-layer/types"

export async function customizeSchema({
parentSpan,
deferNodeMutation,
refresh, // webhookBody,//coming soon
}: Partial<IDataLayerContext>): Promise<void> {
const activity = reporter.activityTimer(`createSchemaCustomization`, {
Expand All @@ -13,6 +14,7 @@ export async function customizeSchema({
await createSchemaCustomization({
parentSpan,
refresh,
deferNodeMutation,
// webhookBody,
})
activity.end()
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby/src/services/post-bootstrap.ts
Expand Up @@ -6,12 +6,16 @@ import { boundActionCreators } from "../redux/actions"

export async function postBootstrap({
parentSpan,
deferNodeMutation,
}: Partial<IDataLayerContext>): Promise<void> {
const activity = reporter.activityTimer(`onPostBootstrap`, {
parentSpan,
})
activity.start()
await apiRunnerNode(`onPostBootstrap`, { parentSpan: activity.span })
await apiRunnerNode(`onPostBootstrap`, {
parentSpan: activity.span,
deferNodeMutation,
})
activity.end()

reporter.info(reporter.stripIndent`
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/state-machines/develop/index.ts
Expand Up @@ -237,6 +237,7 @@ const developConfig: MachineConfig<IBuildContext, any, AnyEventObject> = {
parentSpan,
store,
webhookBody,
refresh: true,
deferNodeMutation: true,
}
},
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby/src/utils/create-schema-customization.ts
Expand Up @@ -5,15 +5,18 @@ import { Span } from "opentracing"
export const createSchemaCustomization = async ({
refresh = false,
parentSpan,
deferNodeMutation,
}: {
refresh?: boolean
parentSpan?: Span
deferNodeMutation?: boolean
}): Promise<void> => {
if (refresh) {
store.dispatch({ type: `CLEAR_SCHEMA_CUSTOMIZATION` })
}
await apiRunnerNode(`createSchemaCustomization`, {
parentSpan,
deferNodeMutation,
traceId: !refresh
? `initial-createSchemaCustomization`
: `refresh-createSchemaCustomization`,
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/start-server.ts
Expand Up @@ -270,7 +270,7 @@ export async function startServer(
}, cors())
}

await apiRunnerNode(`onCreateDevServer`, { app })
await apiRunnerNode(`onCreateDevServer`, { app, deferNodeMutation: true })

// In case nothing before handled hot-update - send 404.
// This fixes "Unexpected token < in JSON at position 0" runtime
Expand Down

0 comments on commit 5e5b413

Please sign in to comment.