Skip to content

Conversation

@aullman
Copy link

@aullman aullman commented Sep 4, 2020

Not sure how you feel about this. I had an issue where I wanted some messages to be retained but any new subscriptions were not getting them because we don't actually create a new subscription for every graphql subscription. This change is keeping the retained messages locally and sending them out to any new graphql subscriptions. We clean up the retained messages when there are no more subscriptions for that topic.

Would love to know if there is a better way to do this...

@davidyaha
Copy link
Owner

Hey @aullman!
Thanks for reaching out.
I think sending retained information should be handled with GraphQL queries rather than using something like graphql-subscriptions...
Could you elaborate more on your use case so that I'd understand why do you need the data to be sent this way?

@aullman
Copy link
Author

aullman commented Sep 4, 2020

Sure, I'm building presence using graphql. Basically storing a lastSeen value for each user every few seconds and then having everyone subscribe to that. Rather than persisting this value I was just using retained mqtt messages so that any new person that comes online and misses an update will get the last one sent by that user. I expected that if I made messages retained then each time I have a new graphql subscription it will give me back the last retained message straight away. This works fine if you are the first person to subscribe to someone's presence but subsequent subscribes are not actually a new mqtt subscribe so mqtt does not send us the retained message. So this change is simulating that for any subsequent subscribes.

I suppose I could do this in my own code instead, but I would have to know whether there was an existing mqtt subscription and make sure I send the update to only that graphql subscription somehow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants