Apollo Request Tracer
Extension for tracing GraphQL query resolution in ApolloServer
Primary motivation of this lib is tracking cold and warm start performance of GraphQL in serverless environments (AWS Lambda, Google Cloud Functions)
Install
yarn add apollo-request-tracer@1.0.2
Usage
// Create a new tracerconst Tracer = ;const tracer = Tracerstart; // Create a timer tracking how long node module import takeslet requireTimer = tracer;const Express = ;const ApolloServer gql = ;const Functions = ;const Models = ;// Stop the timerrequireTimer; // Create a timer tracking how long the initial GraphQL setup takeslet setupTimer = tracer; const typeDefs = gql` type Query { hello(name: String): String }`; const resolvers = Query: hello: async { // Request tracer gets added to resolver context and can be used // for adding timing information specific to that resolver const tracer = context; const timer = tracer; const message = `Hello !`; timer; return message; } ; // Create a new ApolloServer with tracer extension that tracks// the graphql query resolution processconst server = typeDefs resolvers extensions: tracerrequest; const app = ;server; moduleexports = graphql: Functionshttps;; // Stop setup timer and tracersetupTimer;tracer;