👺 Fragment based orm request generator for Hasura with built in auto-table lookup and base fragment builder
MIT License
Bot releases are hidden (Show)
Published by mrspartak over 4 years ago
Published by mrspartak over 4 years ago
Published by mrspartak over 4 years ago
Published by mrspartak over 4 years ago
Published by mrspartak over 4 years ago
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',
}
})
Published by mrspartak over 4 years ago
Because it is a query and then subscribe to get immediate data
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
Published by mrspartak over 4 years ago
To subscribe in browser user
const orm = new Hasura({
...,
wsConnectionSettings: {
webSocketImpl: WebSocket
}
})
Published by mrspartak over 4 years ago
orm.updateParams({
jwt: 'new jwt'
})
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();
Published by mrspartak over 4 years ago
graphql
is critical, so the module subscriptions-transport-ws
will not work without it
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
}
*/
Published by mrspartak over 4 years ago
I hate GhA workflow configs
Published by mrspartak over 4 years ago
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
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)
})
Published by mrspartak over 4 years ago
Docs are still not fully written, but the link will not change
Published by mrspartak over 4 years ago