neogoose
Node.js Neo4j OGM inspired by Mongoose & GraphQL
TLDR
Use GraphQL schema language to define Models. On Model CRUD
input validated & output resolved through a generated GraphQL schema. Modularize your neo4js-graphql-js augmented schema with the additional power of an OGM for further database operations.
Models are not designed to support querying relationships use a session for this. This library is designed to place a CRUD
api over nodes. You can also create an Executable schema to execute more complex queries.
Installation
First install Node.js, then start Neo4j & finally...
$ npm install neogoose
⚠ neo4j-driver
and graphql
are peerDependencies you may need to install them too.
$ npm install neo4j-driver graphql
Importing
const neogoose = ;
Connecting
await neogoose;
Creating Multiple connections
const connection1 = await neogoose;const connection2 = await neogoose;
Disconnecting
await neogoose;
Defining a Model
Models are defined using GraphQL schema language.
const User = neogoose;
Creating a session
await neogoose; // https://neo4j.com/developer/javascript/const session = await neogoose;
Retrieving a model
const user = neogoose;
Executable schema
Compile your models into an neo4js-graphql-js augmented schema
const schema = neogoose;
Transforms made before calling makeAugmentedSchema
constraint
directives removedValidation
directives removed
⚠ All other schema directives here are ignored in neogoose
land
Query
Used with;
findOne
findMany
updateOne
updateMany
deleteOne
deleteMany
count
Equality
const dan = await User;
$or
const users = await User;
$and
const users = await User;
$regex
const users = await User;
⚠ Javascript regex not supported use regex stated here
$in
const users = await User;
Comparison Operators
$eq
$gt
$gte
$in
$lt
$lte
$ne
$nin
Logical Operators
$and
$or
Evaluation Operators
$regex
Skip/Limit
Used with
findMany
updateMany
deleteMany
const paginatedUsers = await User;
Creating nodes
create
createMany
const user = await User; await User
Find nodes
findMany
findOne
const query = name: "Dan"; const users = await User; const dan = await User;
Update nodes
updateOne
updateMany
const query = name: "Dan"; const update = name: "naD"; await User; const user = await User;
Using $set
Regular update will replace all properties use
$set
to+=
properties on the node
const query = name: "Dan"; const update = repo: "neogoose"; const user = await User; username // Danuserrepo // neogoose
Deleting properties
$set to null
const user = await User
Delete nodes
deleteOne
deleteMany
const query = name: "Dan"; await User; const users = await User;
Count nodes
count
const query = name: "Dan"; const userCount = await User;
Resolvers
Records returned from your Neo4j instance are 'pulled' through a GraphQL schema, you can use Resolvers to achieve 'virtuals' on a model.
const User = neogoose;
Selection Set
Select more than Autogenerated Selection Set works well with Resolvers and complex nested types, Used with;
findOne
findMany
updateOne
updateMany
deleteOne
deleteMany
const User = neogoose; const selectionSet = ` { id name email nested { abc } }` const dan = await User; // exists(dan.nested.abc) === true
Autogenerated Selection Set
⚠ If you don't specify Selection Set an auto generated one will be made based on the provided type
.
const User = neogoose; const AUTO_SELECTION_SET = ` { id name email nested # ⚠ ERROR }`
Validation
Built in support for @Validation
directive.
const User = neogoose;
Auto Validation
⚠ If you don't specify @Validation
an auto generated input
will be made based on the provided type
. Nested input
types are not supported!
Before
typeDefs: ` type User { id: ID! name: String! email: String! } `
After
The below is representing the Models auto generated schema if you don't provide
@Validation
directive.
typeDefs: ` input AUTO_GENERATED { # Default if you don't specify properties id: ID! name: String! email: String! } type User @Validation(properties: AUTO_GENERATED) { id: ID! name: String! email: String! } `
Directives
Built in support for graphql-constraint-directive.
const User = neogoose;
⚠ @constraint
directives are removed before augmented schema generation.