https://github.com/Econify/graphql-request-profiler
Easy to use GraphQL performance analysis utility for tracing resolver execution time
https://github.com/Econify/graphql-request-profiler
apollo express express-graphql graphql performance plugin profiler visualizer
Last synced: 10 months ago
JSON representation
Easy to use GraphQL performance analysis utility for tracing resolver execution time
- Host: GitHub
- URL: https://github.com/Econify/graphql-request-profiler
- Owner: Econify
- Created: 2022-05-17T22:58:34.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-07-11T01:13:45.000Z (almost 3 years ago)
- Last Synced: 2025-06-11T20:27:54.634Z (11 months ago)
- Topics: apollo, express, express-graphql, graphql, performance, plugin, profiler, visualizer
- Language: TypeScript
- Homepage:
- Size: 531 KB
- Stars: 56
- Watchers: 3
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# graphql-request-profiler

Easy to use GraphQL performance analysis utility for profiling resolver execution time. Observe resolver execution time in your API with a visualization tool.
## Example
```sh
graphql-request-profiler -s examples/operation.graphql -e http://localhost:4000/graphql
```

## Installation
For CLI usage with API that has the plugin installed:
```sh
npm i -g @econify/graphql-request-profiler
```
Within a project:
```sh
npm install --save @econify/graphql-request-profiler
```
```sh
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
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
```js
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](https://github.com/Econify/graphql-request-profiler/blob/main/packages/plugin/examples/graphql-http/http.ts)
See [example of graphql-http with express](https://github.com/Econify/graphql-request-profiler/blob/main/packages/plugin/examples/graphql-http/express.ts)
### apollo-server
```js
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](https://github.com/Econify/graphql-request-profiler/blob/main/packages/plugin/examples/apollo/index.ts)
#### Deprecated
### express-graphql
```js
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](https://github.com/Econify/graphql-request-profiler/blob/main/packages/plugin/examples/express-graphql/index.ts)
### 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.
```js
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.
```sh
graphql-request-profiler --headerName x-custom-header [...]
```
## Like this package?
Check out Econify's other GraphQL package, [graphql-rest-router](https://www.github.com/Econify/graphql-rest-router), that allows routing to and caching an internal GraphQL API as a self-documenting REST API without exposing the schema!