-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (34 loc) · 1.01 KB
/
index.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
require("./src/database/conection");
const UserModel = require("./src/models/person")
const {typeDefs}= require("./src/types")
const { ApolloServer } = require("apollo-server");
const { ApolloServerPluginLandingPageGraphQLPlayground } = require("apollo-server-core");
const resolvers = {
Query: {
personCount: async () => await UserModel.count(),
allPersons: () => {
return UserModel.find({});
},
findPerson: async (_, { name }) => {
return await UserModel.findOne({ name });
},
},
Mutation: {
createPerson: async (_, { input }) => {
const newPerson = new UserModel(input);
await newPerson.save();
return newPerson;
},
deletePerson:async(_,{id})=>{
return await UserModel.findByIdAndDelete(id)
},
},
};
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [ApolloServerPluginLandingPageGraphQLPlayground()],
});
server.listen({ port: process.env.PORT || 4000 }).then(({ url }) => {
console.log(`Server ready at ${url}`);
});