mirror of
https://github.com/aleleba/create-node-ts-graphql-server.git
synced 2025-01-09 21:46:48 -06:00
Alejandro Lembke Barrientos
b55b0f61a9
Adding files from first version. Creating GraphQL server with their controllers and their models, squema and resolvers. Adding support to webpack and typescript.
30 lines
665 B
TypeScript
30 lines
665 B
TypeScript
'use strict';
|
|
import express from 'express'; //express
|
|
import { graphqlHTTP } from 'express-graphql';
|
|
import { config } from '../config';
|
|
import schema from './schema';
|
|
|
|
const server = express.Router();//Router de Express
|
|
|
|
server.use(
|
|
'/',
|
|
graphqlHTTP( (req, res) => {
|
|
return {
|
|
schema,
|
|
graphiql: config.graphiQL,
|
|
context: { req, res }
|
|
};
|
|
}),
|
|
);
|
|
|
|
|
|
|
|
// DO NOT DO app.listen() unless we're testing this directly
|
|
if (require.main === module) {
|
|
server.listen((process.env.PORT || 4000), () => {
|
|
console.log(`Iniciando Express en el puerto 4000${server.graphqlPath}`); /*${app.get('port')}*/
|
|
});
|
|
}
|
|
|
|
// Instead do export the app:
|
|
export default server; |