-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
46 lines (39 loc) · 1.1 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
40
41
42
43
44
45
46
import express from 'express'
import bodyParser from 'body-parser'
import {
graphqlExpress,
graphiqlExpress,
} from 'apollo-server-express'
import { makeExecutableSchema } from 'graphql-tools'
import mongoose from 'mongoose'
import path from 'path'
import {
fileLoader,
mergeTypes,
mergeResolvers,
} from 'merge-graphql-schemas'
import cors from 'cors'
mongoose.Promise = global.Promise
import models from './models'
const typeDefs = mergeTypes(fileLoader(path.join(__dirname, './types')))
const resolvers = mergeResolvers(fileLoader(path.join(__dirname, './resolvers')))
const schema = makeExecutableSchema({
typeDefs,
resolvers,
})
const PORT = 3000
const app = express ()
app.use(cors({ origin: ['http://localhost:3001'] }))
app.use('/graphql', bodyParser.json(), graphqlExpress({
schema,
context: {
models,
user: {
_id: 1,
username: 'lvelasquez',
},
},
}))
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }))
mongoose.connect('mongodb://localhost:27017/instagram-clone')
.then(() => app.listen(PORT, () => console.log('Running GraphQL Server ...')))