mattkrick / cashay

:moneybag: Relay for the rest of us :moneybag:
MIT License
453 stars 28 forks source link

Remote event driven subscriptions #87

Closed mattkrick closed 8 years ago

mattkrick commented 8 years ago

Per https://github.com/ParabolInc/action/issues/121:

This presents the problem of performing a full requery instead of a query of just the parts we need. We could solve this in 2 ways:

Ideally, the pattern I want to achieve is a multi-user mutation. Currently, when I call a mutation, it mutates the data & gives me a mutation payload. I want to give this same payload to everyone in the same channel. The challenge is that they currently aren't expecting this & don't know what to do with it when they get it.

I see 2 ways to handle this:

I think I like the latter because it's a little more expressive. When I get a tip that the avatar field has changed for someone, I should ask (read "query") for a new version, not mutate my local copy so the requery happens behind the scenes.

This pattern could open up the door to having the client write custom queries (eg pass in fields that you want to fetch & dynamically create an AST which turns into a query string). In Relay, these queries are regarded as static strings that are babelfied before being sent to the client in order to avoid having to send GraphQL + the client schema down. Cashay doesn't have the same constraint, so it might make for a really powerful pattern that hugely differentiates cashay from Relay, or it could be an abuse of power.

jordanh commented 8 years ago

I like this. The trick is going to be how to allow a developer to follow the thread all the way round (subscription creation->mutation->publish->subscriber), but I trust you'll be able to do that.

I love that this minimizes payloads.

I also prefer the forceFetch pattern, it is more expression and – importantly – more obvious.

mattkrick commented 8 years ago

in my head, it goes like this:

The thing I don't like about it is that we're essentially using the presence subscription because it's there. There is no really good reason we don't use the subscriber for meeting, only that we are doing a lot of non-GraphQL stuff in the presence one.

Maybe it makes sense, since every developer will have at least 1 sub that listens for changes, otherwise they'd have to just put everyone on the same channel & blast changes all around, leaving it up to the socket PUBLISH_OUT middleware to block.

mattkrick commented 8 years ago

closed by writing recipes for subscriptions