From 5f19ddbb1b9b411766243443f0da4f2484c3a1b3 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Mon, 9 Nov 2020 16:20:33 +0100 Subject: [PATCH] index.ts: schema without token Signed-off-by: leonnicolas --- package.json | 1 + src/index.ts | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 6db1674..d96339a 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ }, "dependencies": { "apollo-server-express": "^2.17.0", + "body-parser": "^1.19.0", "cors": "^2.8.5", "crc": "^3.8.0", "dotenv": "^8.2.0", diff --git a/src/index.ts b/src/index.ts index 2ac3d02..1369318 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,6 +36,7 @@ import workshopResolvers from './resolvers/workshopResolvers'; import { ActionLog } from './model/ActionLog'; import actionLogResolvers from './resolvers/actionLogResolvers'; import { ActionLogAPI } from './datasources/db/actionLogAPI'; +import bodyParser from 'body-parser'; const cors = require('cors'); require('dotenv').config(); @@ -71,7 +72,9 @@ const connOptions: ConnectionOptions = { * @param next */ async function authenticate (req: any, res: any, next: any) { - if (process.env.NODE_ENV === 'develop') { + if (req.body.operationName === 'IntrospectionQuery') { + next(); + } else if (process.env.NODE_ENV === 'develop') { req.permissions = requiredPermissions.map((e) => e.name); req.userId = await userAPI.getUserId(req.headers.authorization?.replace('Bearer ', '')); next(); @@ -132,6 +135,7 @@ const server = new ApolloServer({ const app = express(); app.use(cors()); +app.use(bodyParser.json()); app.post('/graphql', authenticate); app.get(/\/graphql?&.*query=/, authenticate);