Hej - I’m trying to setup a middleware logger to l...
# orm-help
d
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?
Copy code
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
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
Ahhh. Cheers. I realised I could add it to the express middleware in yoga
Copy code
new GraphQLServer({
  schema: schema
}).use(graphqlQueryLoggerMiddleware)
m
ah yes that’s an option too! great idea 😄