-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathexample.js
97 lines (87 loc) · 2.47 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const { Neo4jGraphQL } = require("@neo4j/graphql");
const { ApolloServer } = require("apollo-server");
const neo4j = require("neo4j-driver");
const driver = neo4j.driver(
"bolt://<HOST>:<BOLTPORT>",
neo4j.auth.basic("<USERNAME>", "<PASSWORD>")
);
const typeDefs = /* GraphQL */ `
type Movie @exclude(operations: [CREATE, UPDATE, DELETE]) {
budget: Int
countries: [String]
imdbId: ID
imdbRating: Float
imdbVotes: Int
languages: [String]
movieId: ID!
plot: String
poster: String
released: String
revenue: Int
runtime: Int
title: String
tmdbId: String
url: String
year: Int
genres: [Genre!]! @relationship(type: "IN_GENRE", direction: OUT)
actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN)
directors: [Director!]! @relationship(type: "DIRECTED", direction: IN)
similar(first: Int = 3): [Movie]
@cypher(
statement: """
MATCH (this)-[:ACTED_IN|:DIRECTED|:IN_GENRE]-(overlap)-[:ACTED_IN|:DIRECTED|:IN_GENRE]-(rec:Movie)
WITH rec, COUNT(*) AS score
RETURN rec ORDER BY score DESC LIMIT $first
"""
)
}
type Genre @exclude(operations: [CREATE, UPDATE, DELETE]) {
name: String
movies: [Movie!]! @relationship(type: "IN_GENRE", direction: IN)
}
type User @exclude(operations: [CREATE, UPDATE, DELETE]) {
userId: ID!
name: String
rated: [Movie!]! @relationship(type: "RATED", direction: OUT)
}
type Actor @exclude(operations: [CREATE, UPDATE, DELETE]) {
bio: String
born: Date
bornIn: String
imdbIb: String
name: String
poster: String
tmdbId: String
url: String
acted_in: [Movie!]! @relationship(type: "ACTED_IN", direction: OUT)
}
type Director @exclude(operations: [CREATE, UPDATE, DELETE]) {
bio: String
bornIn: String
imdbIb: String
name: String
poster: String
tmdbId: String
url: String
directed: [Movie!]! @relationship(type: "DIRECTED", direction: OUT)
}
`;
// Create executable GraphQL schema from GraphQL type definitions,
// using @neo4j/graphql to autogenerate resolvers
const neoSchema = new Neo4jGraphQL({
typeDefs,
debug: true,
});
// Create ApolloServer instance that will serve GraphQL schema created above
// Inject Neo4j driver instance into the context object, which will be passed
// into each (autogenerated) resolver
const server = new ApolloServer({
context: { driver },
schema: neoSchema.schema,
introspection: true,
playground: true,
});
// Start ApolloServer
server.listen().then(({ url }) => {
console.log(`GraphQL server ready at ${url}`);
});