🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

apollo-request-tracer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-request-tracer

Request tracing for Apollo Server

1.0.3
latest
Source
npm
Version published
Weekly downloads
5
-70.59%
Maintainers
1
Weekly downloads
 
Created
Source

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 tracer
const Tracer = require('apollo-request-tracer');
const tracer = Tracer.start();

// Create a timer tracking how long node module import takes
let requireTimer = tracer.time('module_requires');
const Express = require('Express');
const {ApolloServer, gql} = require('apollo-server-express');
const Functions = require('firebase-functions');
const Models = require('./Models');
// Stop the timer
requireTimer.stop();

// Create a timer tracking how long the initial GraphQL setup takes
let setupTimer = tracer.time('graphql_setup');

const typeDefs = gql`
  type Query {
    hello(name: String): String
  }
`;

const resolvers = {
  Query: {
    hello: async (args, context)=> {
      // 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.time('build_hello_message');
      const message = `Hello ${args.name}!`;
      timer.stop();
      return message;
    }
  }
};

// Create a new ApolloServer with tracer extension that tracks
// the graphql query resolution process
const server = new ApolloServer({
  typeDefs,
  resolvers,
  extensions: [tracer.request]
});

const app = Express();
server.applyMiddleware({app, path: '/'});

module.exports = {
  graphql: Functions.https.onRequest(app);
};

// Stop setup timer and tracer
setupTimer.stop();
tracer.stop();

FAQs

Package last updated on 13 Oct 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts