I'm building a back-end web server with Apollo Server Express and Mikro-ORM and following the docs, I found that the fork()
method can be used to get a clean entity manager. I've used the function in the config object as part of the context.
const server = new ApolloServer({
schema,
context: async ({ req }): Promise<Context> => {
const context: Context = {
em: orm.em.fork(),
}
const token = req.headers.authorization || ''
if (token) {
try {
const { uid, } = await auth.verifyIdToken(token)
context.uid = uid
} catch (err) {
console.log(err)
}
}
console.log(context);
return context;
},
playground: true
});
While logging out the context as shown in the code, I found that all the forks are kept in memory (or it seems to be).
Output:
...
{ em: [EntityManager<743>], uid: 'XtaxEqnngWXklT4xOZUNmHbVO2f2' }
{ em: [EntityManager<744>], uid: 'XtaxEqnngWXklT4xOZUNmHbVO2f2' }
{ em: [EntityManager<745>], uid: 'XtaxEqnngWXklT4xOZUNmHbVO2f2' }
{ em: [EntityManager<746>], uid: 'XtaxEqnngWXklT4xOZUNmHbVO2f2' }
{ em: [EntityManager<747>], uid: 'XtaxEqnngWXklT4xOZUNmHbVO2f2' }
My question is if there will be negative consequences as a result of this at some point and if yes, how do I deal with this issue?