Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-inspector/audit-command

Package Overview
Dependencies
Maintainers
3
Versions
484
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-inspector/audit-command - npm Package Compare versions

Comparing version 0.0.0-canary.e5ed377 to 0.0.0-canary.fec2df4

5

index.d.ts
import { GlobalArgs } from '@graphql-inspector/commands';
import type { CalculateOperationComplexityConfig } from '@graphql-inspector/core';
import { Source as DocumentSource } from '@graphql-tools/utils';

@@ -6,2 +7,5 @@ declare const _default: import("@graphql-inspector/commands").CommandFactory<{}, {

detail: boolean;
complexityScalarCost: number;
complexityObjectCost: number;
complexityDepthCostFactor: number;
} & GlobalArgs>;

@@ -12,2 +16,3 @@ export default _default;

detail: boolean;
complexityConfig: CalculateOperationComplexityConfig;
}): void;

41

index.js

@@ -10,2 +10,3 @@ 'use strict';

const core = require('@graphql-inspector/core');
const graphql = require('graphql');
const logger = require('@graphql-inspector/logger');

@@ -32,2 +33,17 @@ const Table = _interopDefault(require('cli-table3'));

},
complexityScalarCost: {
describe: 'The cost per scalar for calculating the complexity score.',
type: 'number',
default: 1,
},
complexityObjectCost: {
describe: 'The cost per object for calculating the complexity score.',
type: 'number',
default: 2,
},
complexityDepthCostFactor: {
describe: 'The cost factor per introduced depth level for calculating the complexity score.',
type: 'number',
default: 1.5,
},
});

@@ -42,3 +58,8 @@ },

});
return handler({ documents, detail: args.detail });
const complexityConfig = {
scalarCost: args.complexityScalarCost,
objectCost: args.complexityObjectCost,
depthCostFactor: args.complexityDepthCostFactor,
};
return handler({ documents, detail: args.detail, complexityConfig });
});

@@ -50,4 +71,6 @@ },

const fragments = new Map();
const fragmentStrings = new Map();
const operations = new Map();
const getFragmentReference = (fragmentName) => fragments.get(fragmentName);
const getFragmentSource = (fragmentName) => fragmentStrings.get(fragmentName);
for (const record of args.documents) {

@@ -58,2 +81,3 @@ if (record.document) {

fragments.set(definition.name.value, definition);
fragmentStrings.set(definition.name.value, graphql.print(definition));
}

@@ -71,2 +95,4 @@ else if (definition.kind === 'OperationDefinition') {

let maxDirectives = 0;
let maxTokenCount = 0;
let maxComplexity = 0;
const results = [];

@@ -77,10 +103,17 @@ for (const [name, operation] of operations.entries()) {

const directives = core.countDirectives(operation, getFragmentReference);
results.push([name, depth, aliases, directives]);
const tokenCount = core.calculateTokenCount({
source: graphql.print(operation),
getReferencedFragmentSource: getFragmentSource,
});
const complexity = core.calculateOperationComplexity(operation, args.complexityConfig, getFragmentReference);
results.push([name, depth, aliases, directives, tokenCount.toFixed(2), complexity]);
maxDepth = Math.max(maxDepth, depth);
maxAliases = Math.max(maxAliases, aliases);
maxDirectives = Math.max(maxDirectives, directives);
maxTokenCount = Math.max(maxTokenCount, tokenCount);
maxComplexity = Math.max(maxComplexity, complexity);
}
if (args.detail) {
const table = new Table({
head: ['Operation Name', 'Depth', 'Aliases', 'Directives'],
head: ['Operation Name', 'Depth', 'Aliases', 'Directives', 'Token Count', 'Complexity Score'],
});

@@ -93,2 +126,4 @@ table.push(...results);

logger.Logger.log(`Maximum directive amount is ${logger.chalk.bold(maxDirectives)}`);
logger.Logger.log(`Maximum token count is ${logger.chalk.bold(maxTokenCount)}`);
logger.Logger.log(`Maximum complexity score is ${logger.chalk.bold(maxComplexity.toFixed(2))}`);
}

@@ -95,0 +130,0 @@

8

package.json
{
"name": "@graphql-inspector/audit-command",
"version": "0.0.0-canary.e5ed377",
"version": "0.0.0-canary.fec2df4",
"description": "Audit Documents in GraphQL Inspector",

@@ -10,5 +10,5 @@ "sideEffects": false,

"dependencies": {
"@graphql-inspector/commands": "0.0.0-canary.e5ed377",
"@graphql-inspector/core": "0.0.0-canary.e5ed377",
"@graphql-inspector/logger": "0.0.0-canary.e5ed377",
"@graphql-inspector/commands": "0.0.0-canary.fec2df4",
"@graphql-inspector/core": "0.0.0-canary.fec2df4",
"@graphql-inspector/logger": "0.0.0-canary.fec2df4",
"cli-table3": "0.6.2",

@@ -15,0 +15,0 @@ "tslib": "^2.0.0"

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc