feathersjs-ecosystem / socketio

[MOVED] The Feathers Socket.io websocket transport plugin
https://github.com/feathersjs/feathers
MIT License
37 stars 14 forks source link

feathers / graphql using REST / Sockets #97

Closed 3kynox closed 6 years ago

3kynox commented 7 years ago

Hello there,

I would thanks at first feathers team and all the work done here; I discovered feathers recently and it's just fun to use it everydays. I'm reading a lot about feathers (including articles from Medium and your blog as well).

I'm trying to integrate a websocket connection close to the working REST / Graphql working one but maybe some required experience from myself is not reached yet.

I started to follow these tutoriel to integrate a working feathers / graphql server : https://github.com/swarthout/feathers-apollo/blob/master/docs/explanation-blog.markdown https://medium.com/fuzz/the-electric-feathersjs-and-apollo-server-the-start-f338a744b34b

and I've been a lot helped by examples in : https://github.com/EuropeanRespiratorySociety/api-ers https://github.com/Akryum/vue-apollo

... as well for the server but also for the client (where I'm using Vue / Quasar framework).

For the websocket subscription, there's something I don't get. I started to follow an example from that repository from the same guy that made VueApollo :

https://github.com/Akryum/apollo-server-example

The example do not use at all feathers but this is the most pertinent example I found.

In my graphql servive file here is what I did :

// Initializes the `graphql` service on path `/graphql`

const graphql = require('graphql-server-express').graphqlExpress;
const graphiql = require('graphql-server-express').graphiqlExpress;
const makeExecutableSchema = require('graphql-tools').makeExecutableSchema;

const SubscriptionServer = require('subscriptions-transport-ws').SubscriptionServer;
const { execute, subscribe } = require('graphql');

const Resolvers = require('./graphql.resolvers');
const Schema = require('./graphql.schema');

module.exports = function () {
  const app = this;

  const executableSchema = makeExecutableSchema({
    typeDefs: Schema,
    resolvers: Resolvers.call(app)
  });

  SubscriptionServer.create(
    {
      schema: executableSchema,
      execute,
      subscribe
    },
    {
      server: app,
      path: '/graphql'
    }
  );

  // Initialize our service with any options it requires
  app.use('/graphql', graphql((req) => {
    return {
      schema: executableSchema,
      context: req.feathers
    };
  }));

  app.use('/graphiql', graphiql({
    endpointURL: '/graphql',
  }));
};

The schema and resolvers could be found here but not yet updated for sockets :

https://github.com/3kynox/BTCT/tree/saas-dev/server/src/services/graphql

I think the above example won't work because I'm using the same route (/graphql) for REST & Sockets, which is what I want. I would like to be able to use the same endpoint both for REST & Sockets.

I'll have to write some more code in the schema and resolver file to include subscription field and implement PubSub from graphql-subscriptions like it is done here :

https://github.com/Akryum/apollo-server-example/blob/master/schema.js

The problem with Akryum example two files is it uses a specific port on a dedicated /subscription endpoint, that deals with graphql on the client but separated from the /graphql rest endpoint I'm using and as said, I would like to uses both rest & websockets on the same endpoint.

Any guidelines to accomplish this ? I'm up to read more docs / examples if there is some related to what I'm doing.

Thanks anyway :)

eddyystop commented 7 years ago

This does not address your question but its related items you might want to be aware of.

(1) We have a Feathers GraphQL adapter ready. The docs have to be written before its released. With it you can define resolvers on the server and pass queries from the client, the basic stuff. Its focus is on Query requests.

The adapter however can also use the schema to generate code for your resolvers. The generated code works with either SQL and non-SQL databases. It uses dataloaders for non-SQL databases for high performance; join-monster for SQL databases.

(2) We are just about to release a new populating hook fastJoin which is heavily inspired by GraphQL. Its very fast. The docs are in progress. https://feathers-plus.github.io/v1/feathers-hooks-common/guide.html

3kynox commented 7 years ago

Interesting to learn from this, but I have no clue where that adapter is ? Maybe needed to wait a bit ? Websockets too ?

This is a lot of questions but this looks like exciting :)

eddyystop commented 7 years ago

I'll post when its released in about 2 weeks.

On Sun, Nov 12, 2017 at 2:09 PM, nox notifications@github.com wrote:

Interesting to learn from this, but I have no clue where that adapter is ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/feathersjs/socketio/issues/97#issuecomment-343759440, or mute the thread https://github.com/notifications/unsubscribe-auth/ABezn47Ndm9wsbv4DWKa4WcfRCAxGoBYks5s10KCgaJpZM4Qa8IY .

3kynox commented 7 years ago

I'm still open to explanations / suggestions about implementing websocket subscriptions.

sklink commented 6 years ago

Any word on the release? I'm happy to dig through the code to figure it out without docs if the adapter is ready.

eddyystop commented 6 years ago

I'm working on reducing what people would need to learn to implement GraphQL. Basically, automating the schemas and resolvers somewhat. The previous docs are complete but a bit daunting.

Will you actually use it? I'm asking because more people have agreed to use it than have actually done so. And each one costs me $7, LOL.

I'm presenly focused on Query. How important is Mutation and Subscriptions to you? (As an aside, I think I would prefer using Feathers for mutations and real-time.)

sklink commented 6 years ago

It's hard to tell ahead of time without seeing the implementation. I'm happy to pay the $7 to take a look at it though. Where's that cost coming from?

I'm starting a new project and would like to use GraphQL but using Feathers as a base gives me the ability to include things like authentication without much overhead.

Feathers also opens up both REST and Socket.io which give us a fallback for existing application integrations.

This part of the project is only the server side for me. I'm using Apollo on the client side with this boilerplate: https://github.com/react-boilerplate/react-boilerplate

Is this a new GraphQL implementation or an Apollo GraphQL connector for Feathers?

eddyystop commented 6 years ago

I don't think it uses any Apollo utils and certainly not Apollo itself.

I sent you a link. There are 3 examples: non-SQL, SQL, both.

I'm adding a graphql option to the generator. That'll make it easier to use GraphQL with existing Feathers service. I can send you a link to that in about a week.