create-node-ts-graphql-server/GraphQL/server.ts
Alejandro Lembke Barrientos b55b0f61a9 PR-448199:
Adding files from first version.
Creating GraphQL server with their controllers and their models, squema and resolvers.
Adding support to webpack and typescript.
2022-05-25 21:08:50 +00:00

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;