Skip to content

Commit

Permalink
fix: change event handlers registration style (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
lyubo authored Mar 11, 2023
1 parent 6ba1648 commit 8a98925
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 139 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"graphql": "14 - 16"
},
"devDependencies": {
"@graphql-tools/schema": "^9.0.16",
"@prisma-labs/prettier-config": "^0.1.0",
"@tsconfig/node16": "^1.0.3",
"@types/body-parser": "^1.19.2",
Expand Down
173 changes: 42 additions & 131 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/graphql-ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,22 @@ export class GraphQLWebSocketClient {
constructor(socket: WebSocket, { onInit, onAcknowledged, onPing, onPong }: SocketHandler) {
this.socket = socket

socket.onopen = async (e) => {
socket.addEventListener('open', async (e) => {
this.socketState.acknowledged = false
this.socketState.subscriptions = {}
socket.send(ConnectionInit(onInit ? await onInit() : null).text)
}
})

socket.onclose = (e) => {
socket.addEventListener('close', (e) => {
this.socketState.acknowledged = false
this.socketState.subscriptions = {}
}
})

socket.onerror = (e) => {
socket.addEventListener('error', (e) => {
console.error(e)
}
})

socket.onmessage = (e) => {
socket.addEventListener('message', (e) => {
try {
const message = parseMessage(e.data)
switch (message.type) {
Expand Down Expand Up @@ -176,7 +176,7 @@ export class GraphQLWebSocketClient {
socket.close(1006)
}
socket.close(4400, `Unknown graphql-ws message.`)
}
})
}

private makeSubscribe<T, V extends Variables, E>(
Expand Down
Loading

0 comments on commit 8a98925

Please sign in to comment.