-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,17 @@ const express = require('express'); | |
const bodyParser = require('body-parser'); | ||
const mongoose = require('mongoose'); | ||
const multer = require('multer'); | ||
|
||
const feedRoutes = require('./routes/feed'); | ||
const authRoutes = require('./routes/auth'); | ||
/** UPDATED CONFIG | ||
* express-graphql => graphql-http | ||
* and express-graphiql-explorer (graphiql) | ||
*/ | ||
const grapqlHttp = require('graphql-http/lib/use/express'); | ||
const graphiql = require('express-graphiql-explorer'); | ||
/** ================================== */ | ||
const graphqlSchema = require('./graphql/schema'); | ||
const graphqlResolver = require('./graphql/resolvers'); | ||
|
||
const app = express(); | ||
/** SOCKET-IO CONFIGURATION */ | ||
const http = require('http'); | ||
const server = http.createServer(app); | ||
/** ======================= */ | ||
|
||
const fileStorage = multer.diskStorage({ | ||
destination: (req, file, cb) => { | ||
|
@@ -56,8 +58,26 @@ app.use((req, res, next) => { | |
next(); | ||
}); | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
leo41271
Author
Owner
|
||
app.use('/feed', feedRoutes); | ||
app.use('/auth', authRoutes); | ||
/** EXPRESS-GRAPHIQL-EXPLORER PACKAGE */ | ||
/** note: /graphiql endpoint */ | ||
app.use( | ||
'/graphiql', | ||
graphiql({ | ||
graphQlEndpoint: '/graphql', | ||
defaultQuery: `query MyQuery {}`, | ||
This comment has been minimized.
Sorry, something went wrong.
leo41271
Author
Owner
|
||
}) | ||
); | ||
/** ================================= */ | ||
|
||
/** GRAPHQL-HTTP CONFIGURATION */ | ||
app.all('/graphql', (req, res) => | ||
grapqlHttp.createHandler({ | ||
schema: graphqlSchema, | ||
rootValue: graphqlResolver, | ||
context: { req, res }, | ||
})(req, res) | ||
); | ||
/** ========================== */ | ||
|
||
app.use((error, req, res, next) => { | ||
console.log(error); | ||
|
@@ -75,13 +95,6 @@ mongoose | |
'mongodb://127.0.0.1:27017/messages?retryWrites=true&authSource=admin' | ||
) | ||
.then(() => { | ||
/** SEE LINES 12-15 -- UPDATED CONFIGURATION */ | ||
const io = require('./socket').init(server); | ||
io.on('connection', (socket) => { | ||
console.log('Client connected.'); | ||
}); | ||
/** ======================================== */ | ||
/** LISTEN TO CUSTOM SERVER INSTANCE */ | ||
server.listen(8080); | ||
app.listen(8080); | ||
}) | ||
.catch((err) => console.log(err)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
hello() { | ||
return { | ||
text: 'Hello World!', | ||
views: 1, | ||
}; | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const { buildSchema } = require('graphql'); | ||
|
||
module.exports = buildSchema(` | ||
type TestData { | ||
text: String! | ||
views: Int! | ||
} | ||
type RootQuery { | ||
hello: TestData! | ||
This comment has been minimized.
Sorry, something went wrong.
leo41271
Author
Owner
|
||
} | ||
schema { | ||
query: RootQuery | ||
} | ||
`); |
1 comment
on commit e48121c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
一般會在 middleware 來進行 validator 。 但現在有了 graphql 故 減少 API 。 後面會將 此部分寫謝進去。
app.use('/feed', feedRoutes);
app.use('/auth', authRoutes);