mirror of
https://github.com/wassname/talk.git
synced 2026-07-11 03:54:02 +08:00
34 lines
750 B
JavaScript
34 lines
750 B
JavaScript
const express = require('express');
|
|
const apollo = require('graphql-server-express');
|
|
|
|
const loaders = require('./loaders');
|
|
const mutators = require('./mutators');
|
|
const schema = require('./schema');
|
|
|
|
const router = express.Router();
|
|
|
|
// GraphQL endpoint.
|
|
router.use('/ql', apollo.graphqlExpress((req) => {
|
|
|
|
let context = {};
|
|
|
|
// Load the current logged in user to `user`, otherwise this'll be null.
|
|
context.user = req.user;
|
|
|
|
// Create the loaders.
|
|
context.loaders = loaders(context);
|
|
|
|
// Create the mutators.
|
|
context.mutators = mutators(context);
|
|
|
|
return {
|
|
schema,
|
|
context
|
|
};
|
|
}));
|
|
|
|
// Interactive graphiql interface.
|
|
router.use('/iql', apollo.graphiqlExpress({endpointURL: '/api/v1/graph/ql'}));
|
|
|
|
module.exports = router;
|