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

feat(gatsby): PQR workers can access inference metadata #31858

Merged
merged 26 commits into from
Jun 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e3b01bb
test(gatsby): check if worker can access node created in different pr…
pieh Jun 4, 2021
65d6fcb
make timeout longer for workerpool tests
pieh Jun 4, 2021
5d96a1c
test fixes from other pr
LekoArts Jun 8, 2021
82197d7
wip: saveStateForWorkers / loadStateInWorker
LekoArts Jun 8, 2021
d80183f
basic functionality + type fixes
LekoArts Jun 8, 2021
737fc8c
Merge branch 'master' into save-read-state-slices
LekoArts Jun 8, 2021
ef99519
wip (failing tests)
LekoArts Jun 9, 2021
9bb2880
revert child
LekoArts Jun 9, 2021
39fc78f
add redux state func
LekoArts Jun 9, 2021
1ce9439
revert early return changes
LekoArts Jun 9, 2021
f5cddaa
Merge remote-tracking branch 'upstream/master' into save-read-state-s…
Jun 9, 2021
5baab54
initial
LekoArts Jun 10, 2021
365fe69
update tests and add env var
LekoArts Jun 10, 2021
ede3674
updates
LekoArts Jun 10, 2021
323301a
Merge branch 'master' into save-read-state-slices
LekoArts Jun 10, 2021
05c6cea
Merge remote-tracking branch 'upstream/master' into save-read-state-s…
Jun 10, 2021
e160e1f
send inference metadata
LekoArts Jun 10, 2021
d8ee774
Merge branch 'master' into pqr-worker-inf-metadata
LekoArts Jun 10, 2021
1828341
Merge remote-tracking branch 'upstream/master' into save-read-state-s…
Jun 10, 2021
342b306
Merge remote-tracking branch 'upstream/master' into pqr-worker-inf-me…
Jun 10, 2021
c75a7d0
ignore all node_modules
pieh Jun 10, 2021
af20d74
rename GatsbyStateSlices type to GatsbyStateKeys to more accurately d…
pieh Jun 10, 2021
871b4c1
Merge remote-tracking branch 'origin/save-read-state-slices' into pqr…
pieh Jun 10, 2021
94dee36
actually fix @babel/register
pieh Jun 10, 2021
ad5b6e9
Merge branch 'master' into pqr-worker-inf-metadata
LekoArts Jun 14, 2021
918479a
Restore pool.ts
LekoArts Jun 14, 2021
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
4 changes: 4 additions & 0 deletions packages/gatsby/src/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export async function bootstrap(

await rebuildSchemaWithSitePage(context)

if (process.env.GATSBY_EXPERIMENTAL_PARALLEL_QUERY_RUNNING) {
saveStateForWorkers([`inferenceMetadata`])
}

await extractQueries(context)

if (process.env.GATSBY_EXPERIMENTAL_PARALLEL_QUERY_RUNNING) {
Expand Down
45 changes: 44 additions & 1 deletion packages/gatsby/src/utils/worker/__tests__/share-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe(`worker (share-state)`, () => {
`)
})

it(`can set slices results into state and access it`, async () => {
it(`can set slices results into state and access page & static queries`, async () => {
worker = createTestWorker()
const staticQueryID = `1`

Expand Down Expand Up @@ -234,4 +234,47 @@ describe(`worker (share-state)`, () => {
}
`)
})

it(`can set slices results into state and access inference metadata`, async () => {
worker = createTestWorker()

store.dispatch({
type: `BUILD_TYPE_METADATA`,
payload: {
typeName: `Test`,
nodes: [
{
id: `1`,
parent: null,
children: [],
foo: `bar`,
internal: { type: `Test` },
},
],
},
})

saveStateForWorkers([`inferenceMetadata`])

await worker.setInferenceMetadata()

const inf = await worker.getInferenceMetadata(`Test`)

expect(inf).toMatchInlineSnapshot(`
Object {
"dirty": true,
"fieldMap": Object {
"foo": Object {
"string": Object {
"example": "bar",
"first": "1",
"total": 1,
},
},
},
"ignoredFields": Object {},
"total": 1,
}
`)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
IGatsbyPageComponent,
IGatsbyStaticQueryComponents,
} from "../../../../redux/types"
import { ITypeMetadata } from "../../../../schema/infer/inference-metadata"
import reporter from "gatsby-cli/lib/reporter"
import apiRunner from "../../../api-runner-node"

Expand Down Expand Up @@ -33,6 +34,9 @@ export function getStaticQueryComponent(
): IGatsbyStaticQueryComponents | undefined {
return store.getState().staticQueryComponents.get(id)
}
export function getInferenceMetadata(typeName: string): ITypeMetadata {
return store.getState().inferenceMetadata.typeMap[typeName]
}

// test: reporter
export function log(message: string): boolean {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/worker/child/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Note: this doesn't check for conflicts between module exports
export { renderHTMLProd, renderHTMLDev } from "./render-html"
export { setQueries } from "./schema"
export { setQueries, setInferenceMetadata } from "./schema"
export { loadConfigAndPlugins } from "./load-config-and-plugins"
3 changes: 3 additions & 0 deletions packages/gatsby/src/utils/worker/child/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { setState } from "./state"

export function setInferenceMetadata(): void {
setState([`inferenceMetadata`])
}
export function setQueries(): void {
setState([`components`, `staticQueryComponents`])
}