Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
graphiql: true,
formatError,
pretty: true,
context: {
request: req, // just for example, pass request to context
dataLoaders: initDataLoaders(),
},
});
// Declare route for batch query
// `graphqlBatchHTTPWrapper` and `graphqlHTTP` return arrow functions.
// For performance reasons, declare it once outside (req, res, next) => {} block,
// rather than for every request. Otherwise, it will result in the garbage collector
// being invoked way more than necessary.
const graphqlBatchMiddleware = graphqlBatchHTTPWrapper(
graphqlHTTP(req => req.graphqlServerSettings)
);
server.use(
'/graphql/batch', // NB: should be before `server.use('/graphql', ...)`
bodyParser.json(),
(req, res, next) => {
req.graphqlServerSettings = graphqlSettingsPerRequest(req); // eslint-disable-line
graphqlBatchMiddleware(req, res, next);
}
);
// Declare standard graphql route
server.use(
'/graphql', // NB: should be after `server.use('/graphql/batch', ...)`)
graphqlHTTP(graphqlSettingsPerRequest)
);