Skip to content

Commit

Permalink
fix(gatsby): set pathPrefix in engines
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Jan 25, 2024
1 parent ac3d6db commit 903659a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/gatsby/src/schema/graphql-engine/bundle-webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ export async function createGraphqlEngineBundle(
reporter: Reporter,
isVerbose?: boolean
): Promise<webpack.Compilation | undefined> {
const state = store.getState()
const pathPrefix = state.program.prefixPaths
? state.config.pathPrefix ?? ``
: ``

const schemaSnapshotString = await fs.readFile(
path.join(rootDir, `.cache`, `schema.gql`),
`utf-8`
Expand All @@ -151,7 +156,7 @@ export async function createGraphqlEngineBundle(

// We force a specific lmdb binary module if we detected a broken lmdb installation or if we detect the presence of an adapter
let forcedLmdbBinaryModule: string | undefined = undefined
if (store.getState().adapter.instance) {
if (state.adapter.instance) {
forcedLmdbBinaryModule = `${lmdbPackage}/node.abi83.glibc.node`
}
// We always force the binary if we've installed an alternative path
Expand Down Expand Up @@ -317,6 +322,7 @@ export async function createGraphqlEngineBundle(
"process.env.GATSBY_SKIP_WRITING_SCHEMA_TO_FILE": `true`,
"process.env.NODE_ENV": JSON.stringify(`production`),
SCHEMA_SNAPSHOT: JSON.stringify(schemaSnapshotString),
PATH_PREFIX: JSON.stringify(pathPrefix),
"process.env.GATSBY_LOGGER": JSON.stringify(`yurnalist`),
"process.env.GATSBY_SLICES": JSON.stringify(
!!process.env.GATSBY_SLICES
Expand Down
22 changes: 22 additions & 0 deletions packages/gatsby/src/schema/graphql-engine/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,34 @@ export class GraphQLEngine {
this.getRunner()
}

private setupPathPrefix(pathPrefix: string): void {
if (pathPrefix) {
store.dispatch({
type: `SET_PROGRAM`,
payload: {
prefixPaths: true,
},
})

store.dispatch({
type: `SET_SITE_CONFIG`,
payload: {
...store.getState().config,
pathPrefix,
},
})
}
}

private async _doGetRunner(): Promise<GraphQLRunner> {
await tracerReadyPromise

const wrapActivity = reporter.phantomActivity(`Initializing GraphQL Engine`)
wrapActivity.start()
try {
// @ts-ignore PATH_PREFIX is being "inlined" by bundler
this.setupPathPrefix(PATH_PREFIX)

// @ts-ignore SCHEMA_SNAPSHOT is being "inlined" by bundler
store.dispatch(actions.createTypes(SCHEMA_SNAPSHOT))

Expand Down

0 comments on commit 903659a

Please sign in to comment.