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

PubSubEngine and AsyncIterator state? #121

Closed
jthegedus opened this issue Dec 4, 2017 · 3 comments
Closed

PubSubEngine and AsyncIterator state? #121

jthegedus opened this issue Dec 4, 2017 · 3 comments
Labels

Comments

@jthegedus
Copy link

jthegedus commented Dec 4, 2017

[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:

  • GraphQL Server
  • PubSubEngine
  • Subscription Transport

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 when publish 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 line this.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 a subId: number which I assume is the same id returned from the PubSub subscribe method. Is the subId 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 the subIds are mapped to the [triggername, onMessage] pair in the pub-sub-engine. I'm confused about where and under which variables the onMessage method is triggered.

@davidyaha any insight would be appreciated.

@jthegedus jthegedus changed the title PubSubEngine unsubscribe method requires number, string is more flexible PubSubEngine unsubscribe method usage? Dec 4, 2017
@jthegedus jthegedus changed the title PubSubEngine unsubscribe method usage? PubSubEngine and AsyncIterator state? Dec 4, 2017
@benseitz
Copy link

benseitz commented Feb 2, 2018

Any news on that? I would also be very interested.

@ghost
Copy link

ghost commented Nov 13, 2019

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

eventEmitter.addListener(eventName, pushValue);
and will execute callbacks once the proper event was triggered

@jthegedus
Copy link
Author

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants