Neogma

A fully type-safe Neo4j OGM for TypeScript

Define models with decorators, build queries with a fluent API, and manage relationships automatically.

/* define the user model and its relationships */
@Node({ label: 'User' })
class UserNode extends NodeEntity {
  @PrimaryKey(Type.String()) id!: string;
  @Property(Type.String()) name!: string;

  @Relationship({ name: 'PLACED', direction: 'out', model: () => OrderNode })
  Orders!: Related<typeof OrderNode>;
}

const Users = neogma.model(UserNode);

/* create a user node, an order node, and their relationship, in one transaction */
const user = await Users.createOne({
  id: '1',
  name: 'Alice',
  Orders: { attributes: [{ id: 'order-1', status: 'confirmed' }] },
});

/* Eager-load relationships in one query */
const found = await Users.findOne({
  where: { name: 'Alice' },
  relationships: { Orders: { where: { target: { status: 'confirmed' } } } },
});
console.log(found?.name);                   // string
console.log(found?.Orders[0].node.status);  // string
// console.log(found?.bogusValue);           // TypeScript error