-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy paths1v5.js
100 lines (90 loc) · 1.75 KB
/
s1v5.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
98
99
100
// Treehouse - Introduction to GraphQL - Stage 1 - Video 5
const { ApolloServer } = require("apollo-server");
const studios = [
{
id: "studio_0",
name: "Paramount",
location: "Hollywood",
movieIds: [
"movie_0",
"movie_1",
"movie_2",
]
},
{
id: "studio_1",
name: "Universal",
location: "Universal City",
movieIds: [
"movie_3",
]
},
];
const movies = [
{
id: "movie_0",
title: "Arachnophobia",
tagline: "Eight legs, two fangs, and an attitude.",
revenue: 53200000,
},
{
id: "movie_1",
title: "Armageddon",
tagline: "Earth. It was fun while it lasted.",
revenue: 553700000,
},
{
id: "movie_2",
title: "Catch Me If You Can",
tagline: "The true story of a real fake.",
revenue: 352100000,
},
{
id: "movie_3",
title: "Christmas Vacation",
tagline: "Yule crack up.",
revenue: 71300000,
},
];
/**
* This typeDefs variable holds our GraphQL Schema. This is the only
* part of this file you need to know about, you can ignore the rest!
*/
const typeDefs = `
type Movie {
id: ID!
title: String!
tagline: String
revenue: Int
studio: Studio
}
type Studio {
id: ID!
name: String!
location: String!
}
type Query {
allMovies: [Movie!]
}
`;
const resolvers = {
Query: {
allMovies: (root, args, context) => {
return movies;
},
},
Movie: {
studio: (root, args, context) => {
return studios.find(studio => {
return studio.movieIds.find(movieId => movieId === root.id);
});
},
}
};
const server = new ApolloServer({
typeDefs,
resolvers
});
server.listen({ port: 3000 }).then(({ url }) => {
console.log(`🚀 Server ready at ${url}`);
});