Skip to content
This repository was archived by the owner on Jan 7, 2023. It is now read-only.

Commit ba2d098

Browse files
committed
chore(Update): version update of neo4j and modified example a bit
1 parent f6e2fd7 commit ba2d098

File tree

4 files changed

+692
-2057
lines changed

4 files changed

+692
-2057
lines changed

README.md

Lines changed: 86 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,33 @@ Open `index.js` and fill configuration
2626
const { CoreModule, setup } = require("@gapi/core");
2727
const { VoyagerModule } = require("@gapi/voyager");
2828
const { Neo4JModule } = require("@rxdi/neo4j");
29-
const { GraphQLObjectType, GraphQLString } = require("graphql");
30-
31-
const UserType = new GraphQLObjectType({
32-
name: "User",
33-
fields: () => ({
34-
name: {
35-
type: GraphQLString
36-
}
37-
})
38-
});
29+
const { makeAugmentedSchema } = require("neo4j-graphql-js");
30+
31+
const typeDefs = `
32+
type Movie {
33+
title: String
34+
year: Int
35+
imdbRating: Float
36+
genres: [Genre] @relation(name: "IN_GENRE", direction: "OUT")
37+
}
38+
type Genre {
39+
name: String
40+
movies: [Movie] @relation(name: "IN_GENRE", direction: "IN")
41+
}
42+
`;
3943

4044
setup({
4145
imports: [
42-
CoreModule.forRoot(),
46+
CoreModule.forRoot({ graphql: { initQuery: false } }),
4347
Neo4JModule.forRoot({
44-
types: [UserType],
48+
schemaOverride: () => makeAugmentedSchema({ typeDefs }),
4549
password: "your-password",
4650
username: "neo4j",
4751
address: "bolt://localhost:7687"
4852
}),
4953
VoyagerModule.forRoot()
5054
]
5155
}).subscribe();
52-
5356
```
5457

5558
#### Start the application
@@ -63,48 +66,91 @@ node index.js
6366

6467

6568

66-
#### Use CRUD operations
69+
#### Open voyager panel
70+
71+
```
72+
http://0.0.0.0:9000/voyager
73+
```
74+
75+
76+
![voyager](https://ipfs.io/ipfs/QmWNEZANeePQLpY9P7AX4Kz6gwt7Z67NsxJhQy6GmXByo5)
77+
78+
79+
#### Open graphiql DevTools
80+
```
81+
http://0.0.0.0:9000/devtools
82+
```
83+
84+
#### Example
85+
86+
1. Create `Movie`
6787

6888
```graphql
69-
mutation mutations {
70-
CreateUser(id:"", name:"") {
71-
id
72-
name
73-
_id
74-
}
75-
DeleteUser(id:"") {
76-
id
77-
name
78-
_id
79-
}
80-
UpdateUser(id:"", name:"") {
81-
id
82-
name
89+
mutation {
90+
CreateMovie(title: "Titanic", year: 1990, imdbRating: 1) {
91+
title
92+
year
93+
genres {
94+
name
95+
}
8396
}
8497
}
98+
```
8599

86-
query queries {
87-
User(id:"", name:"", first: 10, offset: 20, orderBy:id_asc) {
88-
id
100+
2. Create `Genre`
101+
```graphql
102+
mutation {
103+
CreateGenre(name: "Drama") {
89104
name
105+
movies {
106+
title
107+
year
108+
imdbRating
109+
}
90110
}
91111
}
92112
```
93113

114+
3. Create `Relationship` between Genre `Drama` and Movie `Titanic`
94115

95-
#### Open graphiql DevTools
96-
```
97-
http://0.0.0.0:9000/devtools
116+
```graphql
117+
mutation {
118+
AddGenreMovies(from: { title: "Titanic" }, to: { name: "Drama" }) {
119+
from {
120+
title
121+
}
122+
to {
123+
name
124+
}
125+
}
126+
}
98127
```
99128

100-
![dev-tools](https://ipfs.io/ipfs/QmPyMcVqLjyeVVUiYYWmE4PcXh2MvAnKzGhLjdrYVzC9ns)
129+
4. List Genres
101130

131+
```graphql
132+
query {
133+
Genre {
134+
name
135+
movies {
136+
title
137+
}
138+
}
139+
}
140+
```
102141

103-
#### Open voyager panel
142+
5. List Movies
104143

144+
```graphql
145+
query {
146+
Movie {
147+
title
148+
year
149+
genres {
150+
name
151+
}
152+
}
153+
}
105154
```
106-
http://0.0.0.0:9000/voyager
107-
```
108-
109155

110-
![voyager](https://ipfs.io/ipfs/QmWNEZANeePQLpY9P7AX4Kz6gwt7Z67NsxJhQy6GmXByo5)
156+
Notice that both objects are linked

index.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
const { CoreModule, setup } = require('@gapi/core');
2-
const { VoyagerModule } = require('@gapi/voyager');
3-
const { Neo4JModule } = require('@rxdi/neo4j');
4-
const { GraphQLObjectType, GraphQLString } = require('graphql');
1+
const { CoreModule, setup } = require("@gapi/core");
2+
const { VoyagerModule } = require("@gapi/voyager");
3+
const { Neo4JModule } = require("@rxdi/neo4j");
4+
const { makeAugmentedSchema } = require("neo4j-graphql-js");
55

6-
const UserType = new GraphQLObjectType({
7-
name: 'User',
8-
fields: () => ({
9-
id: {
10-
type: GraphQLString
11-
},
12-
name: {
13-
type: GraphQLString
14-
},
15-
})
16-
});
6+
const typeDefs = `
7+
type Movie {
8+
title: String
9+
year: Int
10+
imdbRating: Float
11+
genres: [Genre] @relation(name: "IN_GENRE", direction: "OUT")
12+
}
13+
type Genre {
14+
name: String
15+
movies: [Movie] @relation(name: "IN_GENRE", direction: "IN")
16+
}
17+
`;
1718

1819
setup({
1920
imports: [
20-
CoreModule.forRoot(),
21+
CoreModule.forRoot({ graphql: { initQuery: false } }),
2122
Neo4JModule.forRoot({
22-
types: [UserType],
23-
password: 'your-password',
24-
username: 'neo4j',
25-
address: 'bolt://localhost:7687'
23+
schemaOverride: () => makeAugmentedSchema({ typeDefs}),
24+
password: "your-password",
25+
username: "neo4j",
26+
address: "bolt://localhost:7687"
2627
}),
2728
VoyagerModule.forRoot()
2829
]
29-
}).subscribe();
30+
}).subscribe();

0 commit comments

Comments
 (0)