git clone https://github.com/rxdi/starter-neo4js-typescript
cd starter-neo4js-typescript && npm i
Download Neo4J database https://neo4j.com/download/
Follow the steps and create your Graph using interface provided and set password to it
default username for neo4j is
neo4j
You only need to setup
password
field
import { CoreModule, Module } from "@gapi/core";
import { VoyagerModule } from "@gapi/voyager";
import { Neo4JModule } from "@rxdi/neo4j";
import { AppController } from "./app.controller";
@Module({
controllers: [AppController],
imports: [
CoreModule.forRoot(),
Neo4JModule.forRoot({
password: "your-password",
username: "neo4j",
address: "bolt://localhost:7687"
}),
VoyagerModule.forRoot()
]
})
export class AppModule {}
import { Controller, GraphQLList, Query, Type } from "@gapi/core";
import { graphRequest } from "@rxdi/neo4j";
import { Movie } from "./movie.type";
import { Genre } from "./genre.type";
@Controller()
export class AppController {
@Type(new GraphQLList(Movie))
@Query()
Movie(root, params, ctx, resolveInfo) {
return graphRequest(root, params, ctx, resolveInfo);
}
@Type(new GraphQLList(Genre))
@Query()
Genre(root, params, ctx, resolveInfo) {
return graphRequest(root, params, ctx, resolveInfo);
}
}
import {
GraphQLObjectType,
GraphQLString,
GraphQLInt,
GraphQLFloat,
GraphQLList
} from "graphql";
import { Genre } from "./genre.type";
export const Movie = new GraphQLObjectType({
name: "Movie",
fields: () => ({
title: {
type: GraphQLString
},
year: {
type: GraphQLInt
},
imdbRating: {
type: GraphQLFloat
},
genres: {
relation: {
name: "IN_GANRE",
direction: "OUT"
},
type: new GraphQLList(Genre)
}
})
});
import { GraphQLObjectType, GraphQLString, GraphQLList } from "graphql";
import { Movie } from "./movie.type";
export const Genre = new GraphQLObjectType({
name: "Genre",
fields: () => ({
name: {
type: GraphQLString
},
movies: {
relation: {
name: "IN_GANRE",
direction: "IN"
},
type: new GraphQLList(Movie)
}
})
});
Wait for about 5 seconds and browser will be started leading you to Graphiql panel
npm start
Build is accomplished with ParcelJS internally inside @gapi/cli
npm run build
npm run clean
http://0.0.0.0:9000/voyager
http://0.0.0.0:9000/devtools
- Create
Movie
mutation {
CreateMovie(title: "Titanic", year: 1990, imdbRating: 1) {
title
year
genres {
name
}
}
}
- Create
Genre
mutation {
CreateGenre(name: "Drama") {
name
movies {
title
year
imdbRating
}
}
}
- Create
Relationship
between GenreDrama
and MovieTitanic
mutation {
AddGenreMovies(from: { title: "Titanic" }, to: { name: "Drama" }) {
from {
title
}
to {
name
}
}
}
- List Genres
query {
Genre {
name
movies {
title
}
}
}
- List Movies
query {
Movie {
title
year
genres {
name
}
}
}
Notice that both objects are linked