A library of helper functions to accompany the dgraph-js library.
- 0 dependencies just
dgraph-js
and grpc
are needed as peer dependencies. - 100% test coverage.
- Written in Typescript just like the DGraph library so you get IntelliSense.
- Write one line statements to persist data that would take multiple lines with the base library.
Functions including "commit" indicate they will be set to "commitNow"
Functions including "txn" indicate they create their own transactions and can be directly awaited.
This library is pre 1.0 and there might be some small API changes, that said everything is a small function so you could always ctrl-c ctrl-v it out of the repo if things change.
Example: persist two new nodes, return the node ids
const users = [
{ username: 'foo' }
{ username: 'bar' }
]
const id1 = await xExtractUids(xSetJSONCommitTxn(users, dgraphClient));
Example: upsert helper function
const updateJunior = {
skill: 'Javascript',
level: 10,
x: 'y',
y: 'y',
z: 'y'
};
const existingNode = {
skill: 'Javascript',
level: 10,
x: 'foo',
y: 'foo',
z: 'foo'
};
const updates = [updateJunior];
const upsertFn = basicEqualityUpsertFn(['skill', 'level']);
const [uid] = await xUpsertCommitTxn(upsertFn, updates, dgraphClient);
Checkout all the functions in API documentation
Contribute?
Please do feel free to submit a PR.
Testing
Install docker then run yarn run dgraph-test-db-up
Now just call yarn run test
You can also setup Wallaby JS as a test runner. I am a fan.
Deploy workflow
- Make changes
- Commit those changes
yarn run commit
- Test
yarn run test
- Bump version in
package.json
- Generate changelog
yarn run generate-changelog
- Publish
yarn publish
- Commit
package.json
, CHANGELOG.md
and lib files - Git tag - needed by changelog to know what version to attribute the commits to
- Push