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(server): use file extension in import, fix graphql route registering #9984

Merged
merged 3 commits into from
Feb 9, 2024
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: 1 addition & 1 deletion packages/api-server/src/createServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export async function createServer(options: CreateServerOptions = {}) {
})

if (graphqlFunctionPath) {
const { redwoodFastifyGraphQLServer } = await import('./plugins/graphql')
const { redwoodFastifyGraphQLServer } = await import('./plugins/graphql.js')
// This comes from a babel plugin that's applied to api/dist/functions/graphql.{ts,js} in user projects
const { __rw_graphqlOptions } = await import(
`file://${graphqlFunctionPath}`
Expand Down
14 changes: 10 additions & 4 deletions packages/api-server/src/plugins/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,24 @@ export async function redwoodFastifyGraphQLServer(
return reply
}

const graphqlEndpoint = trimSlashes(yoga.graphqlEndpoint)

const routePaths = ['', '/health', '/readiness', '/stream']
for (const routePath of routePaths) {
fastify.route({
url: `${redwoodOptions.apiRootPath}${yoga.graphqlEndpoint}${routePath}`,
url: `${redwoodOptions.apiRootPath}${graphqlEndpoint}${routePath}`,
method,
handler: (req, reply) => graphQLYogaHandler(req, reply),
})
}

fastify.addHook('onReady', (done) => {
console.info(`GraphQL Yoga Server endpoint at ${yoga.graphqlEndpoint}`)
console.info(`GraphQL Yoga Server endpoint at ${graphqlEndpoint}`)
console.info(
`GraphQL Yoga Server Health Check endpoint at ${yoga.graphqlEndpoint}/health`
`GraphQL Yoga Server Health Check endpoint at ${graphqlEndpoint}/health`
)
console.info(
`GraphQL Yoga Server Readiness endpoint at ${yoga.graphqlEndpoint}/readiness`
`GraphQL Yoga Server Readiness endpoint at ${graphqlEndpoint}/readiness`
)

done()
Expand All @@ -126,3 +128,7 @@ export async function redwoodFastifyGraphQLServer(
console.log(e)
}
}

function trimSlashes(path: string) {
return path.replace(/^\/|\/$/g, '')
}
Loading