Note: This project is looking for maintainers. If you're interested, please create an issue. 🙏
Gverse is an Object Graph Mapper (OGM) for the Dgraph, the high-performance open-source Graph Database. Gverse is written in TypeScript and supports TypeScript 3 and JavaScript ES6.
An OGM enables developers to work with their graph models through idiomatic objects provided by their native programming language. It is similar in concept to Object-Relational Mapping (ORM) libraries such as TypeORM, Sequelize or Hibernate. See Gverse vs ORMs).
The current version of Gverse supports Dgraph version 1.2.x.
For compatibility with Dgraph 1.0.x, use Gverse version 1.0.2. You can specify the version in your packages.json.
Here's a quick start guide to get you up and running.
Make sure you have Dgraph installed and running. This guide assumes you have Dgraph running on default ports (8080 for HTTP and 9080 gRPC).
Gverse requires ES6 with class properties plugin or TypeScript ≥ 2.0.
npm install gverse
or if you prefer, yarn add gverse
. The package includes TypeScript types.
import Gverse from "gverse"
const graph = new Gverse.Graph(
new Gverse.Connection({ host: "localhost", port: 9080 })
)
const indices = `
name: string @index(exact) @lang .
owner: [uid] .
repos: [uid] .
contributors: [uid] .
repositories: [uid] .
`
const types = `
type User {
name
repositories
}
type Repository {
name
contributors
owner
}
`
await graph.applySchema(indices + types)
class User extends Gverse.Vertex {
type = "User"
name: string = ""
}
const user = new User()
user.name = "Zak"
await graph.create(user)
const user = (await graph.get(uid)) as User
console.log(user.name) // = "Zak"
For detailed examples, please see the integration tests under ./test/integration
.
class Repo {
type: "Repository"
name: string
owner: User
contributors: User[]
_edges: {
owner: Edge.toVertex(User),
contributors: Edge.toVertices(User)
}
}
Edges can be directed or undirected (reversible), and can have a cardinality of one or many. For detailed examples, please see the integration tests under ./test/integration
.
The graph.newTransaction().upsert
method enables you to execute upsert block having a query and a mutation:
const query = `{vertex as var(func: eq(name,"John"))}`
const values = {
uid: "uid(vertex)",
name: "Smith"
}
await graph.newTransaction().upsert(query, values)
An optional parameter condition
can be used to run a conditional upsert:
const condition = `eq(len(vertex), 1)`
await graph.newTransaction().upsert(query, values, condition)
Test coverage for Gverse comes from integration tests. Docker and Docker-Compose are required for running integration tests.
./run-integration-tests.sh
Gverse has some fundamental differences to popular ORMs. It's helpful to understand the key differences:
Version | Tag | Published |
---|---|---|
1.2.7 | latest | 1mo ago |