|
| 1 | +# [2.0.0](https://github.com/enisdenjo/graphql-ws/compare/v1.14.0...v2.0.0) (2020-11-20) |
| 2 | + |
| 3 | + |
| 4 | +### Features |
| 5 | + |
| 6 | +* **server:** Make and use with your own flavour ([#64](https://github.com/enisdenjo/graphql-ws/issues/64)) ([38bde87](https://github.com/enisdenjo/graphql-ws/commit/38bde87122f4c39b0357c636fd98bfee886dd6e5)), closes [#61](https://github.com/enisdenjo/graphql-ws/issues/61) [#73](https://github.com/enisdenjo/graphql-ws/issues/73) [#75](https://github.com/enisdenjo/graphql-ws/issues/75) |
| 7 | + |
| 8 | + |
| 9 | +### BREAKING CHANGES |
| 10 | + |
| 11 | +* **server:** You now "make" a ready-to-use server that can be used with _any_ WebSocket implementation! |
| 12 | + |
| 13 | +Summary of breaking changes: |
| 14 | +- No more `keepAlive`. The user should provide its own keep-alive implementation. _(I highly recommend [WebSocket Ping and Pongs](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#Pings_and_Pongs_The_Heartbeat_of_WebSockets))_ |
| 15 | +- No more HTTP `request` in the server context. |
| 16 | +- No more WebSocket in the server context (you're the one that creates it). |
| 17 | +- You use your own WebSocket server |
| 18 | +- Server exports only `makeServer` _(no more `createServer`)_ |
| 19 | + |
| 20 | +### Benefits |
| 21 | +- You're responsible for the server (_any_ optimisation or adjustment can be applied) |
| 22 | +- Any WebSocket server can be used (or even mocked if necessary) |
| 23 | +- You control the disposal of the server (close or transfer clients however you wish) |
| 24 | +- New `extra` field in the `Context` for storing custom values useful for callbacks |
| 25 | +- Full control of authentication flow |
| 26 | +- Full control over error handling |
| 27 | +- True zero-dependency |
| 28 | + |
| 29 | +### Migrating from v1 |
| 30 | + |
| 31 | +**Only the server has to be migrated.** Since this release allows you to use your favourite WebSocket library (or your own implementation), using [ws](https://github.com/websockets/ws) is just one way of using `graphql-ws`. This is how to use the implementation shipped with the lib: |
| 32 | + |
| 33 | +```ts |
| 34 | +/** |
| 35 | + * ❌ instead of the lib creating a WebSocket server internally with the provided arguments |
| 36 | + */ |
| 37 | +import https from 'https'; |
| 38 | +import { createServer } from 'graphql-ws'; |
| 39 | + |
| 40 | +const server = https.createServer(...); |
| 41 | + |
| 42 | +createServer( |
| 43 | + { |
| 44 | + onConnect(ctx) { |
| 45 | + // were previously directly on the context |
| 46 | + ctx.request as IncomingRequest |
| 47 | + ctx.socket as WebSocket |
| 48 | + }, |
| 49 | + ...rest, |
| 50 | + }, |
| 51 | + { |
| 52 | + server, |
| 53 | + path: '/graphql', |
| 54 | + }, |
| 55 | +); |
| 56 | + |
| 57 | +/** |
| 58 | + * ✅ you have to supply the server yourself |
| 59 | + */ |
| 60 | +import https from 'https'; |
| 61 | +import ws from 'ws'; // yarn add ws |
| 62 | +import { useServer } from 'graphql-ws/lib/use/ws'; // notice the import path |
| 63 | + |
| 64 | +const server = https.createServer(...); |
| 65 | +const wsServer = new ws.Server({ |
| 66 | + server, |
| 67 | + path: '/graphql', |
| 68 | +}); |
| 69 | + |
| 70 | +useServer( |
| 71 | + { |
| 72 | + onConnect(ctx) { |
| 73 | + // are now in the `extra` field |
| 74 | + ctx.extra.request as IncomingRequest |
| 75 | + ctx.extra.socket as WebSocket |
| 76 | + }, |
| 77 | + ...rest, |
| 78 | + }, |
| 79 | + wsServer, |
| 80 | + // optional keepAlive with ping pongs (defaults to 12 seconds) |
| 81 | +); |
| 82 | +``` |
| 83 | + |
1 | 84 | # [1.14.0](https://github.com/enisdenjo/graphql-ws/compare/v1.13.1...v1.14.0) (2020-11-15)
|
2 | 85 |
|
3 | 86 |
|
|
0 commit comments