How do I run context initialization for messages in subscriptions? #974
Replies: 1 comment 2 replies
-
I am having exactly the same problem, I haven't found a solution yet, just a work around. What I'm doing is clearing the identity map on each event. That way any queries to the database avoid the cache and I always get fresh data for each event.
Like you said, the entity manager is forked only once per connection, so each user connected gets its own EM instance for the duration of the connection. This is not ideal, since multiple notifications containing multiple asynchronous calls could overlap and the This is the best I could do so far and is good enough for my particular use case. When that doesn't work anymore I'm going to have to avoid db calls and include the data in the message payloads themselves. Also not ideal for other reasons (large payloads). Anyway, I think this issue might be an Apollo server problem itself, I'm not sure it can be fixed in type-graphql, can it? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using TypeGraphQL in a project with MikroORM. Just like in the example, I fork the EM in the context initialization. This works great for queries and mutations.
For subscriptions, this context initialization is not performed (especially not since apollo-server@3 removed build-in subscription support). You can initialize a context on the connection handler of the subscription server, but these are performed once on connection.
What is a good approach to fork the EM for every new message that is handled?
Beta Was this translation helpful? Give feedback.
All reactions