hasura-om

👺 Fragment based orm request generator for Hasura with built in auto-table lookup and base fragment builder

MIT License

Downloads
59
Stars
21
Committers
6

Bot releases are visible (Hide)

hasura-om - Deps version bumps Latest Release

Published by mrspartak over 3 years ago

hasura-om - Security bump try #2

Published by mrspartak over 4 years ago

hasura-om - Security bump

Published by mrspartak over 4 years ago

hasura-om - Pass hasura session vars to query/mutation

Published by mrspartak over 4 years ago

This release allows you to pass headers to special requests. For example if you want to check user's permissions etc.

orm.query({
  message: {
    insert: {
      objects: {
        chat_id: 1,
        message: 'hey'
      }
    }
  }
}, { getFirst: true }, {
  headers: {
    'X-Hasura-User-ID': 1,
    'X-Hasura-Role': 'user',
  }
})
hasura-om - Renamed subscribeToMore - queryAndSubscribe

Published by mrspartak over 4 years ago

Because it is a query and then subscribe to get immediate data

hasura-om - Hasura:subscribeToMore

Published by mrspartak over 4 years ago

Under the hood it makes usual graphql request and then subscribing to new data, skipping first response.

const unsubscribe = this.$orm.subscribeToMore({
  project: {
    fragment: 'list'
  }
}, ([err, response]) => {
//do stuff
}, { skipFirst: false }) //skipFirst = false means you also get first result from subscription
hasura-om - webSocketImpl for broser support

Published by mrspartak over 4 years ago

To subscribe in browser user

const orm = new Hasura({
  ...,
  wsConnectionSettings: {
    webSocketImpl:  WebSocket
  }
})
hasura-om - Can update parameters

Published by mrspartak over 4 years ago

orm.updateParams({
  jwt: 'new jwt'
})
hasura-om - JWT auth support

Published by mrspartak over 4 years ago

This was added to support front-end projects with a bundler. But of course, table autogen will not work

const orm = new Hasura({
  graphqlUrl: process.env.GQL_ENDPOINT,
  jwt: process.env.JWT_TOKEN,
});

orm.createTable({name: '_om_test'})
  .createField({name: 'id', isPrimary: true})
  .createField({name: 'text'})
  .createField({name: 'increment'})
  .createField({name: 'type'})
  .generateBaseFragments();
hasura-om - Critical dependency

Published by mrspartak over 4 years ago

graphql is critical, so the module subscriptions-transport-ws will not work without it

hasura-om - getFirst query modifier

Published by mrspartak over 4 years ago

This query modifier allows you to return the first element of the response array. Very useful, if you select/insert/update only one row, and will get the returning object

let [error, response] = await orm.query({
    user: {
        where: { id: { _eq: 23 } }
    }
}, { getFirst: true })
/* 
response = {
    ...userFields
}
*/
hasura-om - One more try to release

Published by mrspartak over 4 years ago

I hate GhA workflow configs

hasura-om - Fixing release GhA workflow

Published by mrspartak over 4 years ago

hasura-om - Finally a release

Published by mrspartak over 4 years ago

This is the first working release.
A lot of things are to be done later. But the current version is working fine on a server and has a proper documentation

hasura-om - Event emitter for WS connection

Published by mrspartak over 4 years ago

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)
})
hasura-om - Just pushing a link to docs

Published by mrspartak over 4 years ago

Docs are still not fully written, but the link will not change

hasura-om - Bump new realese with fixed test from 0.0.15

Published by mrspartak over 4 years ago

Package Rankings
Top 10.15% on Npmjs.org
Badges
Extracted from project README
NPM Coverage Status XO code style Awesome FOSSA Status NPM package npm bundle size npm npm FOSSA Status