Skip to content

Conversation

@vic
Copy link
Owner

@vic vic commented Jan 24, 2017

Closes #7

@vic vic changed the title [WIP] Feature/subscription WIP: Feature/subscription Jan 24, 2017
@vic vic self-assigned this Jan 24, 2017
@conor-mac-aoidh
Copy link
Collaborator

@vic Great! This will be really useful to me! Thanks, I will do some testing on this later today.

@vic
Copy link
Owner Author

vic commented Jan 24, 2017

@conor-mac-aoidh great! Please let me know if you try this with the example phoenix backend, that would be awesome. Only issue would be that right now, we use the same topic for sending the subscription and for listenning for subscription messages. Middlewares' can now read context.operation which can be "subscription" or "query", so that middlewares can change the context.options.channel.in_msg or anything depending if being used for a subscription or query.

@conor-mac-aoidh
Copy link
Collaborator

@vic Sorry I haven't had a chance to test this yet! The example app does not actually use apollo or apollo-phoenix-websocket, so in order to test it I will have to do some work on the frontend to use those libs. Hopefully I'll get around to it in the next week or so.

@vic
Copy link
Owner Author

vic commented Feb 20, 2017

@conor-mac-aoidh No problem, I've also been not close to the computer this month, hopefully will find some time this or next week to explore this further.

@vic
Copy link
Owner Author

vic commented Apr 21, 2017

Update on this branch progress... [cc @G3z]

Just merged master on this branch, but still not properly subscribing to the backend.

Made a phoenix_chat_example apollo branch on which I'm trying to rewrite the app.js to use APW (apollo-phoenix-websocket). On the APW side, the subscription would be really easy, we would just need to send the subscription document to the server and then use channel.on(msg_name, listener) and forward those messages to the apollo subscription callback.

I was thinking the server would send the message-name under which new subscription data will be received, but looking at the example app.js looks like its always listening for a hardcoded name

@vic
Copy link
Owner Author

vic commented Apr 23, 2017

today I made some changes and got this branch working with the example chat application. Here's how you can help testing this.. (cc @conor-mac-aoidh @G3z)

# clone, or fetch and checkout the feature/subscription branch
git clone [email protected]:vic/apollo-phoenix-websocket --branch feature/subscription
cd apollo-phoenix-websocket
npm install && npm run compile


# then clone my chat app fork on apollo branch
git clone github.com:vic/phoenix_chat_example.git --branch apollo
cd phoenix_chat_example
npm install

# either npm link or just symlink to our recently compiled APW
rm -rf node_modules/apollo-phoenix-websocket
ln -s /path/to/apollo-phoenix-websocket node_modules/

# run the server
mix deps.get
mix phoenix.server

Open two browsers and they should be able to talk to each other.

You might want to take a look at the client side app using APW here (I've renamed the original bare-sockets App as App0 for reference)

On the backend, the only change I made to the original phoenix_chat_example
was this one so that new subscription data gets sent with a different event name -something like ___absinthne__:62335222__- (this way you can get data updates for different gql subscriptions) instead of always getting them on a single subscription:data event as the original code did.

On the client side, and important change is the addition of a required configuration option channel.subscriptionEvent that has the following signature:

(subscriptionResponse, {request, options}) => eventName:String

This function gets called with the resolution of the subscription operation (the chat example generates a new identifier for them that looks like {ref: '___absinthe___:62335222'}). Thus we just extract this ref value so that APW can subscribe to data coming from it.

screen shot 2017-04-22 at 10 00 08 pm

@vic
Copy link
Owner Author

vic commented Apr 23, 2017

Oh forgot to mention, things are highly experimental haha as I didn't implement tests for this :/ and some things like unsubscribing are not implemented.

@harmon25
Copy link

Been following the main Absinthe Subscription issue, your library is mentioned there!

@benwilson512 made the following comment a few weeks back. :
Do note that while apollo-phoenix-websocket will indeed run graphql queries and mutations, it will not run subscriptions it looks like. Nonetheless that project is super handy as far as solving the JS side of the equation. I'm very excited to integrate it with the proof of concept we did of subscriptions in https://github.com/benwilson512/phoenix_chat_example/tree/absinthe

Looks like you did implement it with the POC he is mentioning - may want to jump in that thread and let them know what you have learned!

@vic
Copy link
Owner Author

vic commented Jul 22, 2017

Hey everyone!

Absinthe subscriptions is coming along soon, kudos to @benwilson512 et al. for their awesome work on it. So I've updated this branch and I guess it's finally time to merge it into master.

I've updated the README and released APW 0.6.0, if you have been waiting for GQL websocket subscriptions, this is the moment to try them. I've setup an example app here https://github.com/vic/verily

@vic vic merged commit cff0109 into master Jul 22, 2017
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.

4 participants