Skip to content

Commit

Permalink
write local schema file when configuring server
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis committed Sep 28, 2023
1 parent 80e3e78 commit cf219e5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
2 changes: 0 additions & 2 deletions packages/houdini-react/src/plugin/vite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ export default {
}
}

console.log(rollupConfig)

return {
resolve: {
alias: {
Expand Down
6 changes: 5 additions & 1 deletion packages/houdini/src/lib/router/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function isSecondaryBuild() {
return process.env.HOUDINI_SCHEMA_BUILD === 'true'
}

export async function loadLocalSchema(config: Config): Promise<graphql.GraphQLSchema> {
export async function buildLocalSchema(config: Config): Promise<void> {
// load the current version of vite
const { build } = await import('vite')

Expand Down Expand Up @@ -37,6 +37,10 @@ export async function loadLocalSchema(config: Config): Promise<graphql.GraphQLSc
})

process.env.HOUDINI_SCHEMA_BUILD = 'false'
}

export async function loadLocalSchema(config: Config): Promise<graphql.GraphQLSchema> {
await buildLocalSchema(config)

// import the schema we just built
const { default: schema } = await import(
Expand Down
29 changes: 16 additions & 13 deletions packages/houdini/src/vite/houdini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
routerConventions,
load_manifest,
loadLocalSchema,
buildLocalSchema,
isSecondaryBuild,
} from '../lib'

Expand Down Expand Up @@ -175,11 +176,24 @@ export default function Plugin(opts: PluginConfig = {}): VitePlugin {
},

async configureServer(server) {
for (const plugin of config.plugins) {
if (typeof plugin.vite?.configureServer !== 'function') {
continue
}

await plugin.vite!.configureServer.call(this, {
...server,
houdiniConfig: config,
})
}

// if there is a local schema we need to use that when generating
if (config.localSchema) {
await buildLocalSchema(config)
const { default: schema } = (await server.ssrLoadModule(
path.join(config.localApiDir, '+schema')
)) as { default: graphql.GraphQLSchema }
path.join(config.rootDir, 'temp', 'assets', 'schema.js')
),
{}) as { default: graphql.GraphQLSchema }

config.schema = schema
}
Expand All @@ -192,17 +206,6 @@ export default function Plugin(opts: PluginConfig = {}): VitePlugin {
formatErrors(e)
throw e
}

for (const plugin of config.plugins) {
if (typeof plugin.vite?.configureServer !== 'function') {
continue
}

await plugin.vite!.configureServer.call(this, {
...server,
houdiniConfig: config,
})
}
},

// transform the user's code
Expand Down

0 comments on commit cf219e5

Please sign in to comment.