Cache/memoize schema build for use on serverless/lambdas/functions? #285
Unanswered
orbiteleven
asked this question in
Q&A
Replies: 1 comment 3 replies
-
let httpHandler: (event: APIGatewayProxyEvent, context: Context) => Promise<unknown>;
export const handleHttp = async (event: APIGatewayEvent, context: LambdaContext) => {
if (!httpHandler) {
httpHandler =
// your apollo server handler and build schema code
}
return await httpHandler(event, context);
}; |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Wondering if/how other folks are using
typegraphql-prisma
. I'm currently evaluating a move from Heroku to Vercel or Netlify, though I'm imaging the same problem with occur with any serverless platform like AWS, GCP or Azure.My current setup is a Next.js app which has a single
/api/graphql
route that builds an Apollo server using a schema built bybuildSchema
. I'm memoizing both the schema and Apollo server, but since the route is "serverless" it gets destroyed (along with the memoized schema & server) once requests stop coming in.When I set timers on the various steps, I can see that
buildSchema
takes around 1500ms, leading to significant slow start delays. This is with 15 tables, the largest of which (by far) is 24 columns.How are other folks dealing with this? Seems like we could build the schema once and just import that artifact, but I can't figure out if that functionality exists right now.
Cheers!
Beta Was this translation helpful? Give feedback.
All reactions