-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a021c76
commit 8795ac3
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const { graphqlHTTP } = require('express-graphql') | ||
const { buildSchema } = require('graphql') | ||
const { graphqlUploadExpress } = require('graphql-upload') | ||
const userResolver = require('./resolvers/user.resolver') | ||
const bodyParser = require('body-parser') | ||
const mongoose = require('mongoose') | ||
const express = require('express') | ||
const path = require('path') | ||
require('dotenv').config() | ||
const fs = require('fs') | ||
|
||
mongoose.connect(process.env.MONGODB_URI, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}) | ||
|
||
const schemaPath = path.join(`${__dirname}/graphql`, 'user.graphql') | ||
const schemaContent = fs.readFileSync(schemaPath, 'utf-8') | ||
|
||
const schema = buildSchema(schemaContent) | ||
|
||
const root = { | ||
...userResolver, | ||
} | ||
|
||
const app = express() | ||
const port = 3000 | ||
|
||
app.use(bodyParser.json()) | ||
app.use( | ||
'/graphql', | ||
graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }), | ||
) | ||
app.use( | ||
'/graphql', | ||
graphqlHTTP({ | ||
schema, | ||
rootValue: root, | ||
graphiql: true, | ||
}), | ||
) | ||
|
||
app.listen(port, () => { | ||
console.log(`Server is running on http://localhost:${port}/graphql`) | ||
}) |