Getting Started

This section will help you get started with Neo4j GraphQL OGM. Before starting we recommend readers have an understanding of;

1. Installation

npm install @neo4j/graphql-ogm

graphql and neo4j-driver are are peerDependencies.

2. Requiring

const { OGM } = require("@neo4j/graphql-ogm");

3. REST API Quick Start

This section demonstrates how to use the OGM outside of a GraphQL API. The example exposes a Express server and uses the OGM, in the endpoint, to interact with Neo4j.

const express = require("express");
const { OGM } = require("@neo4j/graphql-ogm");
const neo4j = require("neo4j-driver");

const driver = neo4j.driver(
    "bolt://localhost:7687",
    neo4j.auth.basic("neo4j", "letmein")
);

const typeDefs = `
    type User {
        id: ID
        name: String
    }
`;

const ogm = new OGM({ typeDefs, driver });
const User = ogm.model("User");

const app = express();
app.get("/users", async (req, res) => {
    const { search, skip, limit, sort } = req.query;

    const regex = search ? `(?i).*${search}.*` : null;

    const users = await User.find({
        where: { name_REGEX: regex },
        options: {
            skip,
            limit,
            sort
        }
    });

    return res.json(users).end();
});
app.listen(4000, () => console.log("started"));