
Research
/Security News
Critical Vulnerability in NestJS Devtools: Localhost RCE via Sandbox Escape
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
graphql-log
Advanced tools
graphql-log
Add logging to your GraphQL resolvers so you know what's going on in your app.
Everytime a resolver is executed it logs the full path to the resolver. The output in your terminal (when using the popular debug
module for logging) will be something like this:
server:resolvers Message.channel +0ms
server:resolvers User.avatar +0ms
server:resolvers User.username +0ms
server:resolvers User.avatar +4ms
server:resolvers User.coverPhoto +0ms
server:resolvers User.username +0ms
Note: The "server:resolvers" and "+xms" parts are added by
debug
, this module only logs the path on execution.
This is the simplest example:
// Require the module
const createGraphQLLogger = require('graphql-log');
// Create a logger
const logExecutions = createGraphQLLogger();
// Wrap your resolvers
logExecutions(resolvers);
Note that your resolvers need to be a plain object of resolvers. (like you'd create for graphql-tools
makeExecutableSchema
function)
graphql-log
has some options:
logger
(function, default: console.log
): Use a custom logger like debug
, pino
or any other one.prefix
(string): Prefix all logs with a certain stringconst logExecutions = createGraphQLLogger({
// Prefix all logs with resolvers.
prefix: 'resolvers.',
});
Let's say you want to use the popular debug
module for logging. Doing so would be as easy as passing it into the logger
option:
const debug = require('debug')('server:resolvers');
const logExecutions = createGraphQLLogger({
logger: debug,
});
Logging every execution of every resolver will have a performance impact on your app, so we recommend only enabling this module in development. A common way to do so (depending on your setup) would be something like this:
const createGraphQLLogger = require('graphql-log');
const resolvers = {/*...*/};
if (process.env.NODE_ENV === 'development') {
const logExecutions = createGraphQLLogger();
logExecutions(resolvers);
}
The main thing I want to change is that instead of wrapping the resolvers this module would wrap a finished schema instead. This would make it compatible not only with folks who keep their resolvers separate, but with everybody.
That'd probably look something like this:
// I'd love to be able to pass a schema
logExecutions(schema);
Good first PR?
Licensed under the MIT License, Copyright ©️ 2017 Maximilian Stoiber. See LICENSE.md for more information.
FAQs
Add logging to your GraphQL resolvers.
The npm package graphql-log receives a total of 475 weekly downloads. As such, graphql-log popularity was classified as not popular.
We found that graphql-log demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.
Product
Socket now supports Rust and Cargo, offering package search for all users and experimental SBOM generation for enterprise projects.