Coder Social home page Coder Social logo

Comments (2)

vladshcherbin avatar vladshcherbin commented on May 30, 2024 1

I've played with a few packages, it's actually possible to quickly attach a ws server to existing graphql-api-koa one.

Small overview of findings:

  • subscriptions-transport-ws - most popular, has support in different client libraries, not maintained, has a note to use another library in readme
  • graphql-ws - suggested one to use, has updated specs and is not compatible with above package, well maintained, has support in some client libraries
  • graphql-helix - quite new, allows you to create all parts of graphql server or probably attach to existing one, has support for server-sent-events

I kinda liked server-sent-events idea, but support and tutorials are close to none.
In current project I have android and ios clients, both use apollo libraries which have support only for subscriptions-transport-ws 🤦‍♂️
For now I had to choose it with a plan to switch to graphql-ws once mobile libraries add support, tracking - ios, android

Here is a small example for reference:

websocket server in a separate file

import { execute, subscribe } from 'graphql'
import { SubscriptionServer } from 'subscriptions-transport-ws'
import { schema } from './graphql'

export default function attachSubscriptionsServer(server) {
  SubscriptionServer.create(
    {
      schema,
      execute,
      subscribe
    },
    {
      server,
      path: '/subscriptions'
    }
  )
}

koa server

import { createServer } from 'http'
import Koa from 'koa'
import router from './router'
import attachSubscriptionsServer from './websocket-server'

const app = new Koa()

app.use(router.routes())

const server = createServer(app.callback())

attachSubscriptionsServer(server)

server.listen(process.env.PORT)

from graphql-api-koa.

jaydenseric avatar jaydenseric commented on May 30, 2024

It's not something I've setup in any of my projects so I don't have any code examples to share, but it should be possible to use other GraphQL subscriptions solutions in combination with this package. Could the middleware be setup so if the request relates to subscriptions, the other library (or code, whatever it is) handles the request instead of graphql-api-koa?

I'm not really comfortable endorsing a particular strategy for subscriptions here until I've seriously immersed in the problem space and built something production quality using subscriptions. Back when subscriptions was mostly poorly maintained Apollo tech I wasn't very motivated to adopt it, but now there are a lot higher quality protocols and packages available (particularly by The Guild guys) that are more aligned with the GraphQL Foundation and the open GraphQL ecosystem.

from graphql-api-koa.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.