diff --git a/.github/workflows/npmpublish.yml b/.github/workflows/npmpublish.yml index 135959c..59820ac 100644 --- a/.github/workflows/npmpublish.yml +++ b/.github/workflows/npmpublish.yml @@ -7,15 +7,12 @@ on: jobs: build: runs-on: ubuntu-latest - strategy: - matrix: - node: [ '10', '12' ] - name: Node ${{ matrix.node }} sample + name: Node 12 sample steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: - node-version: ${{ matrix.node }} + node-version: 12 - run: npm install - run: npm test env: diff --git a/README.md b/README.md index 67bb56b..a2f9134 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ # Hasura object mapping library ![Node.js Package](https://github.com/mrspartak/hasura-om/workflows/Node.js%20Package/badge.svg) [![Coverage Status](https://coveralls.io/repos/github/mrspartak/hasura-om/badge.svg?branch=master)](https://coveralls.io/github/mrspartak/hasura-om?branch=master) +# Instalation +``` +npm i hasura-om +``` + # A problem We have a microservice infrastructure and need cross-service transactions. One way to do it is to send a graphql query + variables to one service and perform a query there. So this library helps to send more standardized data via JS Objects. If you know a better way to solve this problem, you are welcome to issues or email. @@ -13,6 +18,8 @@ const om = new Hasura({ graphqlUrl: 'your hasura endpoint', adminSecret: 'your hasura admin secret' }) +//this command loads data from Hasura about tables/fields/keys to build base table fragments for simple queries +await om.init() //query let [err, result] = om.query({ diff --git a/tests/real_query.js b/tests/real_query.js index df8a41c..932c8bf 100644 --- a/tests/real_query.js +++ b/tests/real_query.js @@ -38,6 +38,39 @@ test.serial('delete all records', async (t) => { t.is(typeof response._om_test.delete, 'object'); t.is(typeof response._om_test_types.delete, 'object'); + + //ensure that no rows exist + var [err, response] = await orm.query({ + _om_test: {}, + _om_test_types: {}, + }); + if (err) throw err; + + t.is(response._om_test.length, 0); + t.is(response._om_test_types.length, 0); +}); + +test.serial('test option flatOne', async (t) => { + let orm = t.context.orm; + + var [err, response] = await orm.query({ + _om_test: {}, + }); + if (err) throw err; + + t.is(response.length, 0); + + var [err, response] = await orm.query( + { + _om_test: {}, + }, + { + flatOne: false, + }, + ); + if (err) throw err; + + t.is(response._om_test.length, 0); }); test.serial('add records with transaction', async (t) => {