-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
86 lines (62 loc) · 1.87 KB
/
index.js
File metadata and controls
86 lines (62 loc) · 1.87 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
import express from 'express';
import { ApolloServer,gql } from 'apollo-server-express';
import * as bodyParser from 'body-parser';
import mongoose from 'mongoose';
import cors from 'cors';
import UserTypes from './types/User';
import RestaurantTypes from './types/Restaurent';
import CommonTypes from './types/Common';
import createUser from './resolvers/createUser';
import loginUser from './resolvers/loginUser';
import getAllRestaurants from './resolvers/getAllRestaurants';
import addRestaurant from './resolvers/addRestaurant';
import searchRestaurant from './resolvers/searchRestaurant';
const typeDefs = `
${CommonTypes}
${UserTypes}
${RestaurantTypes}
type Query {
hello : String
loginUser(request : loginUserInput) : loginUserResponse
getAllRestaurants : restaurantsResponse
searchRestaurant(request : searchRestaurantInput!) : restaurantsResponse
}
type Mutation {
createUser(request : createUserInput) : createdUserResponse
addRestaurant(request : restaurantInput) : restaurantResponse
}
`;
const resolvers = {
Query : {
loginUser,
getAllRestaurants,
searchRestaurant
},
Mutation : {
createUser,
addRestaurant
}
}
const server = new ApolloServer({
typeDefs,
resolvers,
context : ({req,res}) => {
return {
req,res
}
}
});
const app = express();
app.use(cors());
const PORT = 4001;
server.applyMiddleware({ app });
mongoose.connect('mongodb://localhost:27017/foodmonster',{ useNewUrlParser : true });
mongoose.connection.on('error',err => {
console.log(`Error in mongoose connection ${err}`);
});
mongoose.connection.on('connected',() => {
console.log("Mongoose connected successfully");
app.listen(PORT, () => {
console.log(`server listening in port ${PORT}`);
});
})