swarthout / feathers-apollo

Feathers and Apollo Server Sample Project
MIT License
176 stars 20 forks source link

Socket.io example? #12

Closed idibidiart closed 7 years ago

idibidiart commented 7 years ago

Great work. Is this repo still up to date?

<<Automatic Socket.io integration (way to use websockets for real-time features before Apollo's solution is completed)>>

Apollo has GQL Subscriptions now but they need better documentation and further refinements. In the meantime, I'd like to try out Feather's socket.io solution. I went thru the tutorial in the docs folder and it seems that everything is setup as REST. Is there a Socket.io example or can you please add one?

swarthout commented 7 years ago

This is taken directly from the feathers documentation. I modified it slightly to work with this project, but if you wanted to get a message every time a new post is created, you could use this:

<!-- index.html -->
<script type="text/javascript" src="socket.io/socket.io.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/core-js/2.1.4/core.min.js"></script>
<script type="text/javascript" src="//unpkg.com/feathers-client@^1.0.0/dist/feathers.js"></script>
<script type="text/javascript">
  var socket = io('http://localhost:3000');
  var app = feathers()
    .configure(feathers.hooks())
    .configure(feathers.socketio(socket));

  var postService = app.service('posts');

  postService.on('created', function(post) {
    console.log('Someone created a post', post);
  });
</script>
idibidiart commented 7 years ago

This looks so simple.

I'll spend some time running the blog app example and reading up on Feathers. I am very high on the simplicity and elegance of this whole GQL+Feathers architecture. I think it's awesome.

Having said that, I'm new to both GQL and Feathers (just heard about Feathers thru this repo as I was looking for a GQL authorization solution that made sense) I've only skimmed through the repo so far and I don't see any client side rendering code (no JSX or HTML), so I assume this is a backend demo that is accessible via GraphiQL? If so, which port/url? ... and the above socket.io setup, which looks amazingly simple, is to go into app.js?

Sorry for needing all this clarification, but I'll come up with suggestions for the Readme that would make things more obvious as I learn more.

swarthout commented 7 years ago

You are correct, this is server side only, and you can access graphiql at localhost:3000/graphiql. The code example I gave you could be put in public/index.html

idibidiart commented 7 years ago

@swarthout how do you add permissions to this such that I can only be notified when I create post not when someone else creates a post (fake scenario, just want to understand how Feathers enforces authorization rules in this case)

idibidiart commented 7 years ago

Answer: Feathers supports event filtering. Closing.