create-graphql-server
create-graphql-server copied to clipboard
Support current apollo subscriptions
Sorry for the lack of PR—working in a generated server with lots of other changes! Latest version of apollo-link-ws uses graphql-ws as the protocol, which isn't supported by
"subscriptions-transport-ws": "0.2.6"

HTTP/1.1 400 Bad Request
Connection: close
X-WebSocket-Reject-Reason: Unsupported protocol.
Fix
package.json
- "subscriptions-transport-ws": "0.2.6"
+ "subscriptions-transport-ws": "^0.9.1"
- "graphql": "0.7.2",
- "graphql-server": "^0.3.2",
- "graphql-server-express": "^0.4.3",
- "graphql-subscriptions": "0.2.0",
- "graphql-tools": "^0.8.2",
+ "graphql": "^0.11.7",
+ "graphql-subscriptions": "^0.5.4",
+ "graphql-tag": "^2.5.0",
+ "graphql-tools": "^2.6.1",
+ "apollo-cache-inmemory": "^1.0.0",
+ "apollo-client": "^2.0.1",
+ "apollo-link-http": "^1.1.0",
+ "apollo-server-express": "^1.2.0",
example resolver:
Subscription: {
githubStars: {
subscribe: () => pubsub.asyncIterator('githubStars')
}
}
server/index.js:
import { execute, subscribe } from 'graphql'
...
SubscriptionServer.create(
{
schema,
execute,
subscribe,
onConnect: connectionParams =>
addModelsToContext({ db, githubAPI, pubsub })
},
{
server: websocketServer
}
)