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

fix(gatsby): Defer node mutation in more APIs #26067

Merged
merged 2 commits into from
Jul 28, 2020
Merged
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
2 changes: 2 additions & 0 deletions packages/gatsby/src/services/create-pages.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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