feat: Add request context middleware for config and dependency injection in hooks (#8480)
This commit is contained in:
@@ -128,6 +128,19 @@ class ParseGraphQLServer {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @static
|
||||
* Allow developers to customize each request with inversion of control/dependency injection
|
||||
*/
|
||||
applyRequestContextMiddleware(api, options) {
|
||||
if (options.requestContextMiddleware) {
|
||||
if (typeof options.requestContextMiddleware !== 'function') {
|
||||
throw new Error('requestContextMiddleware must be a function');
|
||||
}
|
||||
api.use(this.config.graphQLPath, options.requestContextMiddleware);
|
||||
}
|
||||
}
|
||||
|
||||
applyGraphQL(app) {
|
||||
if (!app || !app.use) {
|
||||
requiredParameter('You must provide an Express.js app instance!');
|
||||
@@ -135,6 +148,7 @@ class ParseGraphQLServer {
|
||||
app.use(this.config.graphQLPath, corsMiddleware());
|
||||
app.use(this.config.graphQLPath, handleParseHeaders);
|
||||
app.use(this.config.graphQLPath, handleParseSession);
|
||||
this.applyRequestContextMiddleware(app, this.parseServer.config);
|
||||
app.use(this.config.graphQLPath, handleParseErrors);
|
||||
app.use(
|
||||
this.config.graphQLPath,
|
||||
|
||||
Reference in New Issue
Block a user