Title
d

douglaseggleton

05/01/2018, 7:41 AM
Hej - I’m trying to setup a middleware logger to log each incoming query to the graphql server. It’s giving a log entry per each resolver. Is there a way to only log based on the original top level query?
const logMiddleware: any = async (
  resolve: any,
  parent: any,
  args: any,
  ctx: any,
  info: any): Promise<any> => {
  <http://logger.info|logger.info>(info);
  return resolve();
};

export const server: GraphQLServer = new GraphQLServer({
  schema: schema,
  middlewares: [logMiddleware]
});
m

matic

05/01/2018, 8:55 AM
hey @douglaseggleton 👋 GraphQL Middleware doesn’t support top level middleware. This happens because we apply middleware to each of the fields and not schema directly. During the process of making this library we decided to move desired functionality to
yoga
because we believe this is where it should be implemented. Unfortunately, we haven’t made it available there yet, but be sure to keep an eye on it!
d

douglaseggleton

05/01/2018, 1:29 PM
Ahhh. Cheers. I realised I could add it to the express middleware in yoga
new GraphQLServer({
  schema: schema
}).use(graphqlQueryLoggerMiddleware)
m

matic

05/01/2018, 2:53 PM
ah yes that’s an option too! great idea 😄