@graphql-inspector/audit-command
Advanced tools
Comparing version 0.0.0-canary.36b26d2 to 0.0.0-canary.86df6bb
17
index.js
@@ -10,2 +10,3 @@ 'use strict'; | ||
const core = require('@graphql-inspector/core'); | ||
const graphql = require('graphql'); | ||
const logger = require('@graphql-inspector/logger'); | ||
@@ -68,4 +69,6 @@ const Table = _interopDefault(require('cli-table3')); | ||
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) { | ||
@@ -76,2 +79,3 @@ if (record.document) { | ||
fragments.set(definition.name.value, definition); | ||
fragmentStrings.set(definition.name.value, graphql.print(definition)); | ||
} | ||
@@ -89,2 +93,3 @@ else if (definition.kind === 'OperationDefinition') { | ||
let maxDirectives = 0; | ||
let maxTokenCount = 0; | ||
let maxComplexity = 0; | ||
@@ -96,7 +101,12 @@ const results = []; | ||
const directives = core.countDirectives(operation, getFragmentReference); | ||
const tokenCount = core.calculateTokenCount({ | ||
source: graphql.print(operation), | ||
getReferencedFragmentSource: getFragmentSource, | ||
}); | ||
const complexity = core.calculateOperationComplexity(operation, args.complexityConfig, getFragmentReference); | ||
results.push([name, depth, aliases, directives, complexity]); | ||
results.push([name, depth, aliases, directives, tokenCount, complexity.toFixed(2)]); | ||
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); | ||
@@ -106,3 +116,3 @@ } | ||
const table = new Table({ | ||
head: ['Operation Name', 'Depth', 'Aliases', 'Directives', 'Complexity Score'], | ||
head: ['Operation Name', 'Depth', 'Aliases', 'Directives', 'Token Count', 'Complexity Score'], | ||
}); | ||
@@ -115,3 +125,4 @@ table.push(...results); | ||
logger.Logger.log(`Maximum directive amount is ${logger.chalk.bold(maxDirectives)}`); | ||
logger.Logger.log(`Maximum complexity score is ${logger.chalk.bold(maxComplexity)}`); | ||
logger.Logger.log(`Maximum token count is ${logger.chalk.bold(maxTokenCount)}`); | ||
logger.Logger.log(`Maximum complexity score is ${logger.chalk.bold(maxComplexity.toFixed(2))}`); | ||
} | ||
@@ -118,0 +129,0 @@ |
{ | ||
"name": "@graphql-inspector/audit-command", | ||
"version": "0.0.0-canary.36b26d2", | ||
"version": "0.0.0-canary.86df6bb", | ||
"description": "Audit Documents in GraphQL Inspector", | ||
@@ -10,5 +10,5 @@ "sideEffects": false, | ||
"dependencies": { | ||
"@graphql-inspector/commands": "0.0.0-canary.36b26d2", | ||
"@graphql-inspector/core": "0.0.0-canary.36b26d2", | ||
"@graphql-inspector/logger": "0.0.0-canary.36b26d2", | ||
"@graphql-inspector/commands": "0.0.0-canary.86df6bb", | ||
"@graphql-inspector/core": "0.0.0-canary.86df6bb", | ||
"@graphql-inspector/logger": "0.0.0-canary.86df6bb", | ||
"cli-table3": "0.6.2", | ||
@@ -15,0 +15,0 @@ "tslib": "^2.0.0" |
Sorry, the diff of this file is not supported yet
12370
251
+ Added@graphql-inspector/commands@0.0.0-canary.86df6bb(transitive)
+ Added@graphql-inspector/config@0.0.0-canary.86df6bb(transitive)
+ Added@graphql-inspector/core@0.0.0-canary.86df6bb(transitive)
+ Added@graphql-inspector/loaders@0.0.0-canary.86df6bb(transitive)
+ Added@graphql-inspector/logger@0.0.0-canary.86df6bb(transitive)
- Removed@graphql-inspector/commands@0.0.0-canary.36b26d2(transitive)
- Removed@graphql-inspector/config@0.0.0-canary.36b26d2(transitive)
- Removed@graphql-inspector/core@0.0.0-canary.36b26d2(transitive)
- Removed@graphql-inspector/loaders@0.0.0-canary.36b26d2(transitive)
- Removed@graphql-inspector/logger@0.0.0-canary.36b26d2(transitive)