Skip to content

[RFC] Executor Semantics for Subscriptions #224

Closed
@arunoda

Description

@arunoda

This is a continuation of the discussion carried over #189 and #subscription channel of Slack.

Currently there is not details into how subscription field should work. There were some ideas and I'll try to list them over here.

Option 1 - Rerun the subscription field for each event

In this case, this is exactly just like a mutation and for some event, we run the GraphQL executor and get the result. Then we can send it to the our socket layer.

This is the simplest approach to do it. @eyston did some experiments on this.
See: https://github.com/eyston/graphql-todo-subscriptions

As dan schafer mentioned, this is the way they do subscriptions at Facebook. So, it seems like very well scalable solution.

Option 2 - Passing a observable

Other way is to pass a observable to executor. It could be a NodeJS stream. @jimmy_jia metioned this approach on slack and it. This adds some more liabilities to the executor. some of them are:

  • Provide a public API to get events where we can send to the client
  • Watch the steam and handle the end event
  • Once the subscription started, we may need to send something right away to as the result. Like a subscription id. So, there is a question like who is going to responsible for that. GraphQL or the developer?

How to unsubscribe?

I have a question about the way we do stop subscriptions. This is related to both above options. But we are going with option1, we should handle it outside of the executor anyway.

So, with option2, are we going to add a way to executor by introducing a new type of field?

All of these have pros and cons. I'm looking for some ideas on how Facebook handling these. If so, there might be a good reason.
I hope something similar subscription system will be used at some other companies. Looking forward for comments.

cc @skevy

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions