npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@econify/graphql-request-profiler

v0.2.4

Published

Easy to use GraphQL performance analysis utility for tracing resolver execution time

Downloads

2,130

Readme

graphql-request-profiler

Status Checks

Easy to use GraphQL performance analysis utility for profiling resolver execution time. Observe resolver execution time in your API with a visualization tool.

Example

graphql-request-profiler -s examples/operation.graphql -e http://localhost:4000/graphql

Sample Visualizer

Installation

For CLI usage with API that has the plugin installed:

npm i -g @econify/graphql-request-profiler

Within a project:

npm install --save @econify/graphql-request-profiler
yarn add @econify/graphql-request-profiler

CLI Usage

$ graphql-request-profiler --help
graphql-request-profiler: Visualize your GraphQL resolver execution time - Version 0.2.0

Usage:

  graphql-request-profiler --data <fileName>
  graphql-request-profiler --schema operation.graphql --endpoint=localhost:4000/graphql
  graphql-request-profiler --help

Arguments:

  --schema, -s (file path)        requesting schema file location
  --output, -o (file path)        output request data to file location
  --endpoint, -e (string)         the endpoint of the GraphQL server to request
  --variables, -v (file path)     variables to pass to the GraphQL server
  --operationName, -n (string)    optional, name of the operation to use in the schema
  --headerName, -h (string)       optional, the name of the header to activate

  --data, -d (string)             display an existing trace file
  --help (boolean)                displays this help text

graphql-http

import { createHandler } from 'graphql-http/lib/use/http';
import { createHttpHandlerProfilerPlugin } from '@econify/graphql-request-profiler';

const server = http.createServer((req, res) => {
  if (req.url?.startsWith('/graphql')) {
    createHandler(
      createHttpHandlerProfilerPlugin(req, {
        schema: buildSchema(),
      })
    )(req, res);
  } else {
    res.writeHead(404).end();
  }
});

server.listen(4000);
console.log('Listening to port 4000');

See full running example here See example of graphql-http with express

apollo-server

import { createApolloProfilerPlugin } from '@econify/graphql-request-profiler';

const server = new ApolloServer({
  schema: buildSchema(),
  plugins: [createApolloProfilerPlugin()],
});

server.listen().then(({ url }) => {
  console.log(`Listening on ${url}`);
});

See full running example here

Deprecated

express-graphql

import { createExpressProfilerPlugin } from '@econify/graphql-request-profiler';

const app = express();

app.use(
  '/graphql',
  graphqlHTTP((req) =>
    createExpressProfilerPlugin(req, {
      schema,
      graphiql: true,
    })
  )
);

See full running example here

Custom Activation Header

If the server requires a different HTTP header to activate the plugin besides x-trace, a custom header name can be specified in the configuration to the plugin.

createApolloProfilerPlugin({ headerName: 'x-custom-header' });
createExpressProfilerPlugin(req, options, { headerName: 'x-custom-header' });

A custom plugin activation HTTP header may be specified when using the CLI tool.

graphql-request-profiler --headerName x-custom-header [...]

Like this package?

Check out Econify's other GraphQL package, graphql-rest-router, that allows routing to and caching an internal GraphQL API as a self-documenting REST API without exposing the schema!