Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Pass request (upgradeReq) to ConnectionContext #369

Merged
merged 4 commits into from
Mar 19, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

### vNEXT
- pass `request` (`upgradeReq`) to `ConnectionContext` [PR #369](https://github.com/apollographql/subscriptions-transport-ws/pull/369)

### 0.9.6
- fix shallow cloning on contexts which are classes
Expand Down
2 changes: 2 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type ConnectionContext = {
initPromise?: Promise<any>,
isLegacy: boolean,
socket: WebSocket,
request: IncomingMessage,
operations: {
[opId: string]: ExecutionIterator,
},
Expand Down Expand Up @@ -143,6 +144,7 @@ export class SubscriptionServer {
connectionContext.initPromise = Promise.resolve(true);
connectionContext.isLegacy = false;
connectionContext.socket = socket;
connectionContext.request = request;
connectionContext.operations = {};

const connectionClosedHandler = (error: any) => {
Expand Down
10 changes: 10 additions & 0 deletions src/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1450,6 +1450,16 @@ describe('Server', function () {
}, 200);
});

it('should trigger onConnect with the request available in ConnectionContext', (done) => {
new SubscriptionClient(`ws://localhost:${EVENTS_TEST_PORT}/`);

setTimeout(() => {
assert(eventsOptions.onConnect.calledOnce);
expect(eventsOptions.onConnect.getCall(0).args[2].request).to.be.an.instanceof(IncomingMessage);
done();
}, 200);
});

it('should trigger onConnect and return GQL_CONNECTION_ERROR with error', (done) => {
const connectionCallbackSpy = sinon.spy();

Expand Down