5.3.4 • Published 5 days ago

@neo4j/graphql v5.3.4

Weekly downloads
37
License
Apache-2.0
Repository
-
Last release
5 days ago

@neo4j/graphql

A GraphQL to Cypher query execution layer for Neo4j and JavaScript GraphQL implementations.

  1. Documentation

Installation

npm install @neo4j/graphql

graphql & neo4j-driver are peerDependency(s)

npm install graphql neo4j-driver

Importing

Our TypeScript source is transpiled into Common JS, this means you can use the require syntax;

const { Neo4jGraphQL } = require("@neo4j/graphql");

Quick Start

Create schema and serve over port 4000 using Apollo Server:

const { Neo4jGraphQL } = require("@neo4j/graphql");
const neo4j = require("neo4j-driver");
const { ApolloServer } = require("apollo-server");

const typeDefs = `
    type Movie {
        title: String
        year: Int
        imdbRating: Float
        genres: [Genre!]! @relationship(type: "IN_GENRE", direction: OUT)
    }

    type Genre {
        name: String
        movies: [Movie!]! @relationship(type: "IN_GENRE", direction: IN)
    }
`;

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

const neoSchema = new Neo4jGraphQL({ typeDefs, driver });

async function main() {
    const schema = await neoSchema.getSchema();

    const server = new ApolloServer({
        schema,
        context: ({ req }) => ({ req }),
    });

    await server.listen(4000);

    console.log("Online");
}

Example Queries

Create Movie

mutation {
    createMovies(input: [{ title: "The Matrix", year: 1999, imdbRating: 8.7 }]) {
        movies {
            title
        }
    }
}

Connect to Genre

mutation {
    updateMovies(
        where: { title: "The Matrix" }
        connect: { genres: { where: { node: { OR: [{ name: "Sci-fi" }, { name: "Action" }] } } } }
    ) {
        movies {
            title
        }
    }
}

Create Movie and connect Genre

mutation {
    createMovies(
        input: [
            {
                title: "The Matrix"
                year: 1999
                imdbRating: 8.7
                genres: { connect: { where: { node: { AND: [{ name: "Sci-fi" }, { name: "Action" }] } } } }
            }
        ]
    ) {
        movies {
            title
        }
    }
}

Find Movies with Genres

query {
    movies {
        title
        genres {
            name
        }
    }
}

Auth

Define, nested & related, authorization rules such as; “grant update access to all moderators of a post”;

type User {
    id: ID!
    username: String!
}

type Post {
    id: ID!
    title: String!
    moderator: User @relationship(type: "MODERATES_POST", direction: IN)
}

extend type Post @auth(rules: [{ allow: [{ moderator: { id: "$jwt.sub" } }], operations: [UPDATE] }])

Specify rules on fields;

type User {
    id: ID!
    username: String!
}

extend type User {
    password: String! @auth(rules: [{ OR: [{ allow: { id: "$jwt.sub" } }, { roles: ["admin"] }] }])
}

Use RBAC;

type Customer @auth(rules: [{ operations: [READ], roles: ["read:customer"] }]) {
    id: ID
    name: String
    password: String @auth(rules: [{ operations: [READ], roles: ["admin"] }])
}

type Invoice @auth(rules: [{ operations: [READ], roles: ["read:invoice"] }]) {
    id: ID
    csv: String
    total: Int
}

Licence

Apache 2.0

5.3.4

5 days ago

5.3.3

17 days ago

5.3.2

1 month ago

5.3.1

1 month ago

5.3.0

2 months ago

5.2.0

2 months ago

5.1.0

2 months ago

5.0.1

2 months ago

5.0.0

2 months ago

4.4.6

2 months ago

4.4.5

4 months ago

4.4.4

5 months ago

3.24.0

10 months ago

4.4.1

6 months ago

4.4.0

6 months ago

4.4.3

6 months ago

4.4.2

6 months ago

4.0.0

8 months ago

3.24.2

9 months ago

3.24.1

9 months ago

3.24.3

8 months ago

4.3.2

7 months ago

4.3.1

7 months ago

4.3.4

7 months ago

4.3.3

7 months ago

4.3.0

7 months ago

4.2.0

7 months ago

3.23.1

10 months ago

3.23.0

10 months ago

4.0.0-beta.2

9 months ago

4.0.0-beta.1

9 months ago

4.0.0-beta.0

10 months ago

4.1.3

8 months ago

4.1.0

8 months ago

4.1.2

8 months ago

4.1.1

8 months ago

3.22.0

10 months ago

3.20.0

12 months ago

3.20.1

11 months ago

3.19.0

12 months ago

3.21.0

11 months ago

3.18.3

12 months ago

3.17.2

1 year ago

3.17.1

1 year ago

3.18.1

1 year ago

3.18.0

1 year ago

3.18.2

1 year ago

3.17.0

1 year ago

3.16.1

1 year ago

3.16.0

1 year ago

3.15.0

1 year ago

3.13.1

1 year ago

3.14.1

1 year ago

3.14.0

1 year ago

3.14.2

1 year ago

3.12.1

1 year ago

3.12.2

1 year ago

3.13.0

1 year ago

3.9.0

2 years ago

3.10.1

2 years ago

3.10.0

2 years ago

3.12.0

2 years ago

3.11.0

2 years ago

3.11.1

2 years ago

3.8.0

2 years ago

3.7.0

2 years ago

3.4.0

2 years ago

3.6.2

2 years ago

3.6.1

2 years ago

3.6.0

2 years ago

3.6.3

2 years ago

3.5.1

2 years ago

3.5.0

2 years ago

3.2.2

2 years ago

3.2.1

2 years ago

3.2.0

2 years ago

3.2.3

2 years ago

3.3.0

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.1.0

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

2.5.6

2 years ago

2.5.5

2 years ago

2.5.8

2 years ago

2.5.7

2 years ago

3.0.0

2 years ago

2.5.9

2 years ago

2.5.0

2 years ago

2.4.0

2 years ago

2.5.2

2 years ago

2.5.1

2 years ago

2.5.4

2 years ago

2.5.3

2 years ago

2.3.0

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

2.0.0-rc.2

3 years ago

2.0.0-rc.1

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

2.0.0-alpha.4

3 years ago

1.2.2

3 years ago

2.0.0-alpha.3

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.3

3 years ago

2.0.0-alpha.2

3 years ago

2.0.0-alpha.1

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.0-beta.3

3 years ago

1.0.0-beta.2

3 years ago

1.0.0-beta.1

3 years ago

1.0.0-alpha.6

3 years ago

1.0.0-alpha.5

3 years ago

1.0.0-alpha.4

3 years ago

1.0.0-alpha.3

3 years ago

1.0.0-alpha.2

3 years ago

1.0.0-alpha.1

3 years ago