ivome / graphql-relay-php

A library to help construct a graphql-php server supporting react-relay.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Promise Support

ivome opened this issue · comments

Currently we don't have support for Promises. Any suggestions for which library to use for that?

I assume you're talking about implementing subscriptions?

This is going to be an interesting thing to implement for sure. Could you draw inspiration from the way Laravel handles websocket connections? In case you're not familiar with how it works, here's the documentation.

It's a Redis pub/sub model with a simple Node.js server that watches for messages to be pushed to Redis from your PHP app, and sends them to any subscribers.

As w/ @bcarroll22 I'm not sure if you mean subscriptions, but if so this is something I was looking into myself. I'm working w/ Laravel as well, and it has great event/broadcasting functionality built in, but it does require some sort of 3rd party support to handle the websocket portion of it (i.e., Node & Redis).

Last I looked, the GraphQL/Relay subscription implementation was still in a state of flux (no pun intended) and I haven't come across documentation yet. However, I would assume that we need some sort of access to session data so we can tell who subscribed to what channels, as well has have the ability to block subscribing to channels that aren't authorized. So far, the only PHP implementation I've come across that can take care of this would be Rachet's WAMP Server. It does require ZeroMQ (which has been a bit of a pain to install). I've integrated it into a Laravel application and used the built in broadcasting to push messages and it all worked quite well. Didn't get into authorization/session data with it, but I believe it's doable.

One other alternative would be Pusher, albeit a paid service. They mention on the features page that they support Access control/authentication, so it might be a viable solution as well.

If you have links to any example repos that implement subscriptions w/ Relay please send them my way, I'd really like to see how we can get this to work!

In the original repository, there are no subscriptions in this package. It just has support to return JS Promises, I assume they are then used to implement subscriptions.
I don't think this package is the right place for the subscription support though, since I want to keep that as close to the original repository as possible.
I think that is better placed at the lower level in graphql-php so that we have a general support for subscriptions, not only for the Relay specific helpers from this library.

There is already a discussion going on: webonyx/graphql-php#9

The Promises could be implemented as part of this package, if we can agree on a library to use. Would be best if the graphql-php server could then handle the Promise objects that are returned by the functions.

Something like this here could do the job: https://github.com/guzzle/promises
But that only makes sense if the graphql-php library can handle that.

Unfortunately, PHP does not realy make it easy...

I understand what you're talking about now, my bad. That is indeed a very hard problem to solve with PHP. The Guzzle promises package seems like the most elegant solution to me, and I think it would be amazing if the webonyx package implemented support for it as well.

If it was implemented in this package would it be a significant amount of work to make it happen in the graphql package as well?

There is a new proposal in the graphql-php library for implementing promises: webonyx/graphql-php#42

Once that is implemented, we can add it here too.