👺 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
const fragment2 = new Fragment({
table: 'test',
name: 'with_nested_args',
fields: [
'id',
[
'logo',
['url'],
{
_table: 'images',
limit: 'logo_limit',
offset: 'logo_offset',
where: 'logo_where',
order_by: 'logo_order_by',
distinct_on: 'logo_distinct_on',
},
],
],
});
/*
This will generate such fragment
Fragment with_nested_args_fragment_test on test {
id
logo (limit: $logo_limit, ...) {
url
}
}
*/
await orm.query({
test: {
fragment: 'with_nested_args',
variables: {
'logo_limit': 1
}
}
})
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
So queries are select by default, but you can aggregate now
orm.query({
aggregate: {
count
}
})
//response.count
I added pk fragment, that contents only a primary keys and also flat works for mutations too now
orm.mutate({
user: {
insert: {
object: {...newUser},
fragment: 'pk'
}
}
})
//response[0].id
Global flat settings are at Hasura constructor now:
const orm = new Hasura({
...settings,
query: {
flatOne: false
}
})
Published by mrspartak over 4 years ago
//you can use nested array to do this
[
'id',
[
'logo',
[
'url'
]
]
]
/*
id
logo {
url
}
*/
Published by mrspartak over 4 years ago
Use them as easy as:
let unsub = om.subscribe({
user: {
where: {
is_live: {
_eq: true
}
}
}
}, ([err, data]) => {
//so data will come in the same format as the query
})
Published by mrspartak over 4 years ago
Published by mrspartak over 4 years ago
Still not documented, sorry
Published by mrspartak over 4 years ago
An example from Readme
let baseUserFragment = orm.table('user').fragment('base')
let basePostFragment = orm.table('post').fragment('base')
orm.table('user').createFragment('some_unique_name', [
baseUserFragment.gqlFields(),
{
key: 'posts',
values: [
basePostFragment.gqlFields(),
]
}
])
/*
This will create schema with all base user and posts fields
{
...userfields
posts {
...postsfields
}
}
*/
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
Nothing to say, failing to post
Published by mrspartak over 4 years ago
This is still draft release, but it works
Published by mrspartak over 4 years ago
Just a draft to test npm publish