Skip to content

Event emitter for WS connection

Pre-release
Pre-release
Compare
Choose a tag to compare
@mrspartak mrspartak released this 26 May 19:29
· 109 commits to master since this release

So now you can track all events for debugging

const { Hasura } = require('hasura-om')

let orm = new Hasura({
  graphqlUrl: '',
  adminSecret: ''
})
await orm.init()

let unsub = await orm.subscribe({
    _om_test: {
        aggregate: {
            count: {}
        }
    },
}, ([err, data]) => {
        console.log('sub.data', err, data)  
})

let tsStart = new Date().getTime()
let timediff = function () {
    return `+${ ((new Date().getTime() - tsStart)/1000).toFixed(2) }s`
}
orm.$ws.on('connected', () => {
    console.log(timediff(), 'orm.$ws.on.connected')
})
orm.$ws.on('connecting', () => {
    console.log(timediff(), 'orm.$ws.on.connecting')
})
orm.$ws.on('reconnected', () => {
    console.log(timediff(), 'orm.$ws.on.reconnected')
})
orm.$ws.on('reconnecting', () => {
    console.log(timediff(), 'orm.$ws.on.reconnecting')
})
orm.$ws.on('disconnected', () => {
    console.log(timediff(), 'orm.$ws.on.disconnected')
})
orm.$ws.on('error', (data) => {
    console.log(timediff(), 'orm.$ws.on.error', data)
})