Comments (2)
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.
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)
- babel eslint parser missing? HOT 1
- Add possibility to reformat error in errorHandler HOT 13
- Resolver error status code is not respected HOT 2
- Use in Typescript HOT 1
- graphql peer dependency 0.13.1 ? HOT 2
- The presence of errors should not discard data HOT 1
- Add format error functionality HOT 1
- [email protected] HOT 1
- Better schema validation error output HOT 2
- Add information to docs on how to add additional fields in error HOT 2
- Support graphql v15 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphql-api-koa.