import { graphqlHTTP } from "./express-graphql"; import { ExecutionArgs, ExecutionResult, DocumentNode, GraphQLSchema } from "graphql"; import { MSeriesServer } from "./mSeriesServer"; import path from "path"; import { express as voyagerMiddleware } from 'graphql-voyager/middleware'; const express = require('express'); const app = express(); const cors = require('cors') const MyGraphQLDummySchema = new GraphQLSchema({}); let mSeriesDevServer = new MSeriesServer(); function getGqlString(doc: DocumentNode) { return doc.loc && doc.loc.source.body; } const pjson = require('../package.json'); app.use(cors()) app.use( '/graphql', graphqlHTTP({ schema: MyGraphQLDummySchema, graphiql: true, customExecuteFn: async (args: ExecutionArgs) => { const str = getGqlString(args.document)!; const result = await mSeriesDevServer.sendMessage(str) as ExecutionResult; return result } }), ); app.get('/ping', (req: any, res: any) => { return res.send('pong'); }); app.get('/voyager1', (req: any, res: any) => { res.sendFile(path.join(__dirname, '../', 'web', 'voyager.html')); }); app.use('/voyager', voyagerMiddleware({ endpointUrl: '/graphql' })); app.listen(3001); const PORT = 4000; console.log(`Version: ${pjson.version} - Start Listen on web browser on port ${PORT} - http://localhost:${PORT}/graphql`); app.listen(PORT);