-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
176 lines (154 loc) · 3.72 KB
/
Copy pathserver.js
File metadata and controls
176 lines (154 loc) · 3.72 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import {ApolloServer, gql} from "apollo-server";
import fetch from "node-fetch";
//Query => GET /api/tweets/ - all tweets
//Mutation => POST DELETE PUT /api/tweets/ - create tweet
let tweets =[
{
id: "1",
text: "Hello World",
auther: "1"
},
{
id: "2",
text: "Hello World 2",
auther: "2"
}
]
let users = [
{
id: "1",
firstName: "Bob",
lastName: "Bobsky"
},
{
id: "2",
firstName: "Jill",
lastName: "Wayne"
}
]
const typeDefs = gql`
"""
주석이 달린다니 아주 흥미롭군요
"""
type Tweet {
id: ID!
text: String!
auther: User
}
type Query {
"""
모두조회
"""
allMovies: [Movie!]!
movie(id: Int!): Movie
allTweets: [Tweet!]!
tweet(id: ID!): Tweet
allUsers: [User!]!
}
type Mutation {
"""
추가하는 애
"""
postTweet(text: String!, userId : ID!): Tweet!
"""
지우는애
"""
deleteTweet(id: ID!): Boolean!
}
"""
주석이 달린다니 아주 흥미롭군요222
"""
type User {
id: ID!
fullName: String!
firstName: String!
lastName: String!
}
type Movie {
id: Int!
url: String!
imdb_code: String!
title: String!
title_english: String!
title_long: String!
slug: String!
year: Int!
rating: Float!
runtime: Float!
genres: [String]!
summary: String
description_full: String!
synopsis: String
yt_trailer_code: String!
language: String!
background_image: String!
background_image_original: String!
small_cover_image: String!
medium_cover_image: String!
large_cover_image: String!
}
`;
const resolvers = {
Query : {
allTweets(){
return tweets;
},
tweet(root, args){
console.log(args);
return tweets.find(tweet => tweet.id === args.id);
},
allUsers(){
return users;
},
allMovies: async () => {
return fetch("https://yts.torrentbay.to/api/v2/list_movies.json",{
headers: {
'Content-Type': 'application/json',
},
})
.then((r) => r.json())
.then((json) => json.data.movies);
},
movie(_, {id}) {
return fetch(`https://yts.torrentbay.to/api/v2/movie_details.json?movie_id=${id}`,{
headers: {
'Content-Type': 'application/json',
},
})
.then((r) => r.json())
.then((json) => json.data.movie);
}
},
Mutation : {
postTweet(_, {text, userId}){
const newTweet = {
id: (tweets.length + 1).toString(),
text
};
tweets.push(newTweet);
return newTweet;
},
deleteTweet(_, {id}) {
const tweet = tweets.find(tweet => tweet.id === id);
if (!tweet) {
return false;
}
tweets = tweets.filter(tweet => tweet.id !== id);
return true;
},
},
User: {
fullName(user){
return `${user.firstName} ${user.lastName}`;
},
},
Tweet: {
auther(tweet) {
return users.find(user => user.id === tweet.auther);
}
},
}
const server = new ApolloServer({ typeDefs, resolvers });
server.listen().then(({url}) => {
console.log(`🚀 Server ready at ${url}`);
});