graphql-python / flask-graphql

Adds GraphQL support to your Flask application.
MIT License
1.32k stars 139 forks source link

Subscriptions in flask-graphql #24

Open willdeuschle opened 7 years ago

willdeuschle commented 7 years ago

Is there any plan to implement this / are you accepting pull requests?

syrusakbary commented 7 years ago

Hi @willdeuschle, graphql-core and graphene are waiting on the Subscriptions RFC in GraphQL (https://github.com/facebook/graphql/pull/267) to be defined and standardized from the community.

Once that is done, we will start the work :)

kavink commented 6 years ago

@syrusakbary @willdeuschle Looks like graphql-core/graphene has subscriptions support ? Is there an example to refer of an flask app using subscriptions?

paunovic commented 6 years ago

Bump. Is there a working example on how to implement subscriptions in Flask-GraphQL? I've tried some things with Gevents but nothing worked.

rshk commented 6 years ago

I'm using subscriptions via graphql-ws. See example: https://github.com/rshk/yawc/

Messages are forwarded to subscriptions via a Redis PUB/SUB (this allows scaling to >1 app/websocket server).

HOWEVER, I'm still having some trouble figuring out how to properly deal with those RxPy Observable objects. As it is right now it works BUT it will create a new Redis connection / subscription for every new GraphQL subscription, and it will never close them, even when the websocket is closed on the client side.

I'm assuming there's some way the Observer can signal to the Observable when to stop, but I haven't find how it's supposed to work yet. This assuming things are done properly in graphql-ws, i.e. it's not missing some call that's supposed to signal to the observer when to stop.

What I would like to do btw is to actually have one redis subscription per process, and just dispatch the messages internally to all the subscriptions that are currently listening. This to reduce the amount of unnecessary traffic (and as a bonus make it work on the free heroku-redis plan).

Any suggestions are welcome, maybe the graphql-ws authors have some hints about how to make this work?

rshk commented 6 years ago

Looks like this does the trick: https://github.com/rshk/yawc/commit/95d6e50a87f83f37eb5d97a7ba9143ace8870e5f

(It will basically make all subscriptions listen from the same Observable, so it definitely stops countless Redis connections from being created / never disposed of).

dtamez commented 5 years ago

@syrusakbary Since the spec has been updated (https://github.com/graphql/graphql-spec/pull/267) has work begun on adding support for subscriptions in flask-graphql?

babaMar commented 4 years ago

@syrusakbary Since the spec has been updated (graphql/graphql-spec#267) has work begun on adding support for subscriptions in flask-graphql?

doesn't seem so