# @mathix420/graphql

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

Latest version **2.5.10** (published 2022-07-16) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @mathix420/graphql
pnpm add @mathix420/graphql
yarn add @mathix420/graphql
bun add @mathix420/graphql
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.5.10 |
| Published | 2022-07-16 |
| First published | 2021-07-04 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 14 |
| Unpacked size | 8.7 MB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| Author | Neo4j Inc. |
| Maintainers | mathix420 |
| Keywords | neo4j, graphql, server |

## Links

- npm: https://www.npmjs.com/package/@mathix420/graphql
- Homepage: https://github.com/neo4j/graphql/tree/master/packages/graphql
- Issues: https://github.com/neo4j/graphql/issues
- npm.io page: https://npm.io/package/@mathix420/graphql

## Dependencies (14)

- [debug](https://npm.io/package/debug.md) ^4.3.2
- [semver](https://npm.io/package/semver.md) ^7.3.5
- [dot-prop](https://npm.io/package/dot-prop.md) ^6.0.1
- [jwks-rsa](https://npm.io/package/jwks-rsa.md) ^2.0.5
- [camelcase](https://npm.io/package/camelcase.md) ^6.2.0
- [pluralize](https://npm.io/package/pluralize.md) ^8.0.0
- [deep-equal](https://npm.io/package/deep-equal.md) ^2.0.5
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.5.1
- [graphql-relay](https://npm.io/package/graphql-relay.md) ^0.8.0
- [graphql-compose](https://npm.io/package/graphql-compose.md) 9.0.4
- [@graphql-tools/merge](https://npm.io/package/@graphql-tools/merge.md) 6.2.14
- [@graphql-tools/utils](https://npm.io/package/@graphql-tools/utils.md) ^7.10.0
- [@graphql-tools/schema](https://npm.io/package/@graphql-tools/schema.md) ^7.1.5
- [graphql-parse-resolve-info](https://npm.io/package/graphql-parse-resolve-info.md) ^4.12.0

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 2.5.10 (latest) — 2022-07-16
- 2.5.9 — 2022-03-23
- 2.0.6 — 2021-08-19
- 2.0.5 — 2021-08-19
- 2.0.4 — 2021-08-19
- 2.0.3 — 2021-07-29
- 2.0.2 — 2021-07-25
- 2.0.1 — 2021-07-24
- 2.0.0-alpha.5 — 2021-07-17
- 2.0.0-alpha.4 — 2021-07-17
- 2.0.0-alpha.3 — 2021-07-17
- 1.0.5 — 2021-07-04
- 1.0.4 — 2021-07-04
- 1.0.3 — 2021-07-04

## README

# @mathix420/graphql

<p align="center">
  <a href="https://badge.fury.io/js/%40neo4j%2Fgraphql">
    <img alt="npm package" src="https://badge.fury.io/js/%40neo4j%2Fgraphql.svg">
  </a>
  <a href="https://discord.gg/neo4j">
    <img alt="Discord" src="https://img.shields.io/discord/787399249741479977?logo=discord&logoColor=white">
  </a>
  <a href="https://community.neo4j.com/c/drivers-stacks/graphql/33">
    <img alt="Discourse users" src="https://img.shields.io/discourse/users?logo=discourse&server=https%3A%2F%2Fcommunity.neo4j.com">
  </a>
</p>

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

1. [Documentation](https://neo4j.com/docs/graphql-manual/current/)

## Installation

```
$ npm install @mathix420/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;

```js
const { Neo4jGraphQL } = require("@mathix420/graphql");
```

## Quick Start

Create schema and serve over port 4000 using Apollo Server:

```js
const { Neo4jGraphQL } = require("@mathix420/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 neoSchema = new Neo4jGraphQL({ typeDefs, driver });

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

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

server.listen(4000).then(() => console.log("Online"));
```

## Example Queries

### Create Movie

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

### Connect to Genre

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

### Create Movie and connect Genre

```graphql
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

```graphql
query {
    movies {
        title
        genres {
            name
        }
    }
}
```

## Auth

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

```graphql
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;

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

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

Use RBAC;

```graphql
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](https://github.com/neo4j/graphql/blob/master/packages/graphql/LICENSE.txt)

---
_Source: https://npm.io/package/@mathix420/graphql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
