GithubHelp home page GithubHelp logo

wegiangb / neo4j-graphql-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from neo4j-graphql/neo4j-graphql-js

0.0 2.0 0.0 1.2 MB

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

Home Page: https://www.npmjs.com/package/neo4j-graphql-js

License: Other

JavaScript 99.48% Shell 0.52%

neo4j-graphql-js's Introduction

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 in active development. There are rough edges and APIs may change. Please file issues for any bugs that you find or feature requests.

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

Test

We use the ava test runner.

npm install
npm build
npm test

The npm test script will run unit tests that check GraphQL -> Cypher translation and the schema augmentation features and can be easily run locally without a test environment. Full integration tests can be found in /test and are run on CircleCI as part of the CI process.

Examples

See /examples

Full docs can be found on GRANDstack.io/docs

neo4j-graphql-js's People

Contributors

johnymontana avatar michaeldgraham avatar cooperka avatar arne-at-daten-und-bass avatar judas-christ avatar moxious avatar whostolebenfrog avatar sys13 avatar duske avatar fwanicka avatar kipz avatar bebbi avatar pantharshit00 avatar edgesoft avatar jexp avatar sboorlagadda avatar smkhalsa avatar

Watchers

James Cloos avatar Gordon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.