git clone https://github.com/rxdi/starter-neo4js-javascript
cd starter-neo4js-javascript && 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
Open index.js
and fill configuration
const { CoreModule, setup } = require("@gapi/core");
const { VoyagerModule } = require("@gapi/voyager");
const { Neo4JModule } = require("@rxdi/neo4j");
const { makeAugmentedSchema } = require("neo4j-graphql-js");
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")
}
`;
setup({
imports: [
CoreModule.forRoot({ graphql: { initQuery: false } }),
Neo4JModule.forRoot({
schemaOverride: () => makeAugmentedSchema({ typeDefs }),
password: "your-password",
username: "neo4j",
address: "bolt://localhost:7687"
}),
VoyagerModule.forRoot()
]
}).subscribe();
Wait for about 5 seconds and browser will be started leading you to Graphiql panel
node index.js
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