Skip to content

Instantly share code, notes, and snippets.

@rajeshkrishnakumar
Last active November 16, 2021 06:11
Show Gist options
  • Save rajeshkrishnakumar/e66a0e30b667304183d1b4ed268cb8bb to your computer and use it in GitHub Desktop.
Save rajeshkrishnakumar/e66a0e30b667304183d1b4ed268cb8bb to your computer and use it in GitHub Desktop.
newrelic graphQL monitoring middleware
import newrelic from "newrelic";
/**
instead of
import newrelic from 'newrelic';
use this if you get error newrelic.setTransactionName is not a function or _newrelic.default.setTransactionName is not a function
import newrelic from 'newrelic/index';
**/
const processRequest = async (resolve, root, args, context, info) => {
newrelic.setTransactionName(info.fieldName);
return resolve(root, args, context, info);
};
const graphqlMiddleware = {
Query: processRequest,
Mutation: processRequest,
};
export default graphqlMiddleware;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment