2.19.4 • Published 3 years ago

neo4j-graphql-js v2.19.4

Weekly downloads
4,551
License
Apache-2.0
Repository
github
Last release
3 years ago

⚠️ NOTE: This project is no longer actively maintained. Please consider using the official Neo4j GraphQL Library.

CI status npm version Docs link

neo4j-graphql.js

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

neo4j-graphql.js is facilitated by Neo4j Labs.

Installation and usage

Install

npm install --save neo4j-graphql-js

Usage

Start with GraphQL type definitions:

const typeDefs = `
type Movie {
    title: String
    year: Int
    imdbRating: Float
    genres: [Genre] @relation(name: "IN_GENRE", direction: "OUT")
}
type Genre {
    name: String
    movies: [Movie] @relation(name: "IN_GENRE", direction: "IN")
}
`;

Create an executable schema with auto-generated resolvers for Query and Mutation types, ordering, pagination, and support for computed fields defined using the @cypher GraphQL schema directive:

import { makeAugmentedSchema } from 'neo4j-graphql-js';

const schema = makeAugmentedSchema({ typeDefs });

Create a neo4j-javascript-driver instance:

import { v1 as neo4j } from 'neo4j-driver';

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

Use your favorite JavaScript GraphQL server implementation to serve your GraphQL schema, injecting the Neo4j driver instance into the context so your data can be resolved in Neo4j:

import { ApolloServer } from 'apollo-server';

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

server.listen(3003, '0.0.0.0').then(({ url }) => {
  console.log(`GraphQL API ready at ${url}`);
});

If you don't want auto-generated resolvers, you can also call neo4jgraphql() in your GraphQL resolver. Your GraphQL query will be translated to Cypher and the query passed to Neo4j.

import { neo4jgraphql } from 'neo4j-graphql-js';

const resolvers = {
  Query: {
    Movie(object, params, ctx, resolveInfo) {
      return neo4jgraphql(object, params, ctx, resolveInfo);
    }
  }
};

What is neo4j-graphql.js

A package to make it easier to use GraphQL and Neo4j together. neo4j-graphql.js translates GraphQL queries to a single Cypher query, eliminating the need to write queries in GraphQL resolvers and for batching queries. It also exposes the Cypher query language through GraphQL via the @cypher schema directive.

Goals

  • Translate GraphQL queries to Cypher to simplify the process of writing GraphQL resolvers
  • Allow for custom logic by overriding of any resolver function
  • Work with graphql-tools, graphql-js, and apollo-server
  • Support GraphQL servers that need to resolve data from multiple data services/databases
  • Expose the power of Cypher through GraphQL via the @cypher directive

Benefits

  • Send a single query to the database
  • No need to write queries for each resolver
  • Exposes the power of the Cypher query language through GraphQL

Contributing

See our detailed contribution guidelines.

Examples

See /examples

Documentation

Full docs can be found in docs/

Debugging and Tuning

You can log out the generated cypher statements with an environment variable:

DEBUG=neo4j-graphql-js node yourcode.js

This helps to debug and optimize your database statements. E.g. visit your Neo4J browser console at http://localhost:7474/browser/ and paste the following:

:params :params { offset: 0, first: 12, filter: {}, cypherParams: { currentUserId: '42' } }

and now profile the generated query:

EXPLAIN MATCH (`post`:`Post`) WITH `post` ORDER BY post.createdAt DESC RETURN `post` { .id , .title } AS `post`

You can learn more by typing:

:help EXPLAIN
:help params
2.19.4

3 years ago

2.19.3

3 years ago

2.19.2

3 years ago

2.19.1

3 years ago

2.19.0

3 years ago

2.19.0-alpha.0

3 years ago

2.19.0-peer.0

3 years ago

2.18.0

3 years ago

2.17.1

3 years ago

2.17.0

4 years ago

2.16.4

4 years ago

2.16.3

4 years ago

2.16.2

4 years ago

2.16.1

4 years ago

2.16.0

4 years ago

2.15.1

4 years ago

2.15.0

4 years ago

2.14.4

4 years ago

2.14.3

4 years ago

2.14.3-alpha.1

4 years ago

2.14.2

4 years ago

2.14.1-alpha.2

4 years ago

2.14.1-alpha.1

4 years ago

2.14.1

4 years ago

2.14.0

4 years ago

2.13.0

4 years ago

2.12.1

4 years ago

2.12.0

4 years ago

2.11.5

4 years ago

2.11.4

4 years ago

2.11.3

4 years ago

2.11.2

4 years ago

2.11.1

4 years ago

2.11.0

4 years ago

2.10.2

4 years ago

2.10.1

4 years ago

2.10.0

4 years ago

2.9.3

4 years ago

2.9.2

4 years ago

2.9.1

4 years ago

2.9.0

4 years ago

2.8.0

5 years ago

2.7.2

5 years ago

2.7.1

5 years ago

2.7.0

5 years ago

2.6.3

5 years ago

2.6.2

5 years ago

2.6.1

5 years ago

2.6.0

5 years ago

2.5.0

5 years ago

2.4.2

5 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.0

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.33

6 years ago

0.1.32

6 years ago

0.1.31

6 years ago

0.1.30

6 years ago

0.1.29

6 years ago

0.1.28

6 years ago

0.1.27

6 years ago

0.1.26

6 years ago

0.1.25

6 years ago

0.1.24

6 years ago

0.1.23

6 years ago

0.1.22

6 years ago

0.1.21

6 years ago

0.1.20

6 years ago

0.1.19

6 years ago

0.1.18

6 years ago

0.1.17

6 years ago

0.1.16

6 years ago

0.1.15

6 years ago

0.1.14

6 years ago

0.1.13

6 years ago

0.1.12

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago