Closed jthegedus closed 4 years ago
Any news on that? I would also be very interested.
Hi @jthegedus PubSubEngine is just abstract class which is describing interface or "contract" for others to implement. It will allow to create libraries like graphql-redis-subscriptions
and others which are able to work with graphql server without modifications - because they all implements same interface...
To your second question, on what code is executed when you publish something - it basically depends on what you are listening, if you did not created triggers for which you are publishing event, then nothing happens, otherwise async iterator created listeners here https://github.com/apollographql/graphql-subscriptions/blob/e57f4eb6e5a544ac6b5c63aaed9d7b50b21e858f/src/event-emitter-to-async-iterator.ts#L41 and will execute callbacks once the proper event was triggered
@dusan-dragon Thanks for your response.
I was trying to get to the bottom of where the state of the subscription->event pairing was stored and whether or not a plugin would be able to configure that location.
@benseitz Feel free to reopen if you have any unanswered questions from this thread.
[Edit] I'm going to do some more reading and see if I can figure this out myself. Will update with answers or a more succinct question once I've done so. Essentially I want to know the following. What state is kept and how are things triggered (shown in code, not just some diagram) across these parts of a GraphQL Subscription Server:
Firstly, can someone please clarify the purpose of the PubSubEngine for me. Is it meant to notify other instances of the GraphQL server that a subscribe event needs to fire, or is it's
publish
used to fire the subscribe event on the current instance, or both? If it indeed does fire the subscribe event whenpublish
is called, what GraphQL server code is then executed next? How does this call ultimately get to the point where it pushes data to the client?What code in the GraphQL server gets executed during/after
publish
is called? Eg, in this repo, what's executed by this linethis.ee.emit(triggerName, payload);
I also have some questions about how the state is managed across the PubSubEngine and AsyncIterator.
For instance, in the
unsubscribe
method of the PubSubEngine, the signature says it requires asubId: number
which I assume is the same id returned from the PubSubsubscribe
method. Is thesubId
being passed solely from the async-iterator?I see in the
graphql-redis-subscriptions
that the async-iterator stores a list of the subscription ids and the event names, and then thesubIds
are mapped to the[triggername, onMessage]
pair in the pub-sub-engine. I'm confused about where and under which variables theonMessage
method is triggered.@davidyaha any insight would be appreciated.