Express 在graphqlHTTP.middleware之后装载中间件

Express 在graphqlHTTP.middleware之后装载中间件,express,graphql,middleware,graphql-js,express-graphql,Express,Graphql,Middleware,Graphql Js,Express Graphql,我有一个关于expressgraphql的问题。 我正在尝试在GraphQL解析器之后运行中间件 这是我最初的两次尝试: app.use('/api', graphqlHTTP({ schema: graphqlSchema }) ); app.use((req, res, next) => { console.log('middleware called'); next(); }); 及 两者都不起作用。 我猜expressgraphql没有在某处调用next()

我有一个关于
expressgraphql
的问题。 我正在尝试在GraphQL解析器之后运行中间件

这是我最初的两次尝试:

app.use('/api', graphqlHTTP({
    schema: graphqlSchema
  })
);

app.use((req, res, next) => {
  console.log('middleware called');
  next();
});

两者都不起作用。 我猜
expressgraphql
没有在某处调用
next()

消息人士似乎证实了这一点:

type Middleware = (request: Request, response: Response) => void;
next
不是参数

我尝试了以下解决方法:

app.use( (req, res, next) => {
  req.on('end', () => {
    console.log('middleware called');
  });
  next();
});

app.use('/api', graphqlHTTP({
    schema: graphqlSchema
  })
);
这有点管用。但在实际使用中,我注意到,由于突变而改变的数据在回调中还不可用(即已经更新)。如果我将代码包装在
setTimeout
中,数据将更新

底线:如何让中间件(或任何代码)在解析器之后运行

app.use( (req, res, next) => {
  req.on('end', () => {
    console.log('middleware called');
  });
  next();
});

app.use('/api', graphqlHTTP({
    schema: graphqlSchema
  })
);