-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
59 lines (54 loc) · 1.32 KB
/
server.js
File metadata and controls
59 lines (54 loc) · 1.32 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
import {ApolloServer, gql} from "apollo-server";
import {ApolloServerPluginLandingPageLocalDefault} from "apollo-server-core";
// Create your defination first
const typeDefs = gql`
type Movie {
id: Int,
title:String,
year: Int
}
type Query {
movies: [Movie]
movie: Movie
}
type Mutation {
createMovie(title: String!): Boolean
deleteMovie(title: String!): Boolean
}
`;
// With ! we will requir the particular field doesn't return null.
// A map of functions which return data for the schema.
const resolvers = {
Query: {
movies: () => [],
movie: () => ({title: "Hello", year: 2021}),
},
Mutation: {
// createMovie: (root, args, context, info) => "",
createMovie: (_, args) => {
console.log(args)
return true
},
deleteMovie: (_, args) => {
console.log(args)
return true
},
}
};
const server = new ApolloServer({
typeDefs,
resolvers,
csrfPrevention: true,
cache: 'bounded',
plugin: [
ApolloServerPluginLandingPageLocalDefault({ embed: true })
]
})
server
.listen()
.then(() => {
console.log('🚀 app running at http://localhost:4000')
})
.catch((err) => {
console.log(err);
});