Skip to content

Commit

Permalink
fix(server): store the intial request in the context
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Aug 26, 2020
1 parent 747bf5c commit 6927ee0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/server.ts
Expand Up @@ -132,6 +132,11 @@ export interface ServerOptions {

export interface Context {
readonly socket: WebSocket;
/**
* The initial HTTP request before the actual
* socket and connection is established.
*/
readonly request: http.IncomingMessage;
/**
* Indicates that the `ConnectionInit` message
* has been received by the server. If this is
Expand Down Expand Up @@ -187,7 +192,7 @@ export function createServer(
? websocketOptionsOrServer
: new WebSocket.Server(websocketOptionsOrServer);

function handleConnection(socket: WebSocket, _request: http.IncomingMessage) {
function handleConnection(socket: WebSocket, request: http.IncomingMessage) {
if (
socket.protocol === undefined ||
socket.protocol !== GRAPHQL_TRANSPORT_WS_PROTOCOL ||
Expand All @@ -202,6 +207,7 @@ export function createServer(
const ctxRef: { current: Context } = {
current: {
socket,
request,
connectionInitReceived: false,
acknowledged: false,
subscriptions: {},
Expand Down

0 comments on commit 6927ee0

Please sign in to comment.