@graphql-inspector/validate-command
Advanced tools
Comparing version 0.0.0-canary.36985fe to 0.0.0-canary.36b26d2
@@ -5,3 +5,3 @@ import { GlobalArgs, CommandFactory } from '@graphql-inspector/commands'; | ||
export { CommandFactory }; | ||
export declare function handler({ schema, documents, strictFragments, maxDepth, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }: { | ||
export declare function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }: { | ||
schema: GraphQLSchema; | ||
@@ -14,2 +14,4 @@ documents: DocumentSource[]; | ||
maxDepth?: number; | ||
maxDirectiveCount?: number; | ||
maxAliasCount?: number; | ||
filter?: string[]; | ||
@@ -29,2 +31,4 @@ onlyErrors?: boolean; | ||
maxDepth?: number | undefined; | ||
maxAliasCount?: number | undefined; | ||
maxDirectiveCount?: number | undefined; | ||
filter?: string[] | undefined; | ||
@@ -31,0 +35,0 @@ onlyErrors?: boolean | undefined; |
41
index.js
@@ -13,6 +13,8 @@ 'use strict'; | ||
function handler({ schema, documents, strictFragments, maxDepth, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }) { | ||
let invalidDocuments = core.validate(schema, documents.map((doc) => new graphql.Source(graphql.print(doc.document), doc.location)), { | ||
function handler({ schema, documents, strictFragments, maxDepth, maxDirectiveCount, maxAliasCount, apollo, keepClientFields, failOnDeprecated, filter, onlyErrors, relativePaths, output, silent, }) { | ||
let invalidDocuments = core.validate(schema, documents.map(doc => new graphql.Source(graphql.print(doc.document), doc.location)), { | ||
strictFragments, | ||
maxDepth, | ||
maxAliasCount, | ||
maxDirectiveCount, | ||
apollo, | ||
@@ -63,3 +65,3 @@ keepClientFields, | ||
function moveDeprecatedToErrors(docs) { | ||
return docs.map((doc) => { | ||
return docs.map(doc => { | ||
var _a, _b; | ||
@@ -74,3 +76,3 @@ return ({ | ||
function useRelativePaths(docs) { | ||
return docs.map((doc) => { | ||
return docs.map(doc => { | ||
doc.source.name = path.relative(process.cwd(), doc.source.name); | ||
@@ -84,5 +86,5 @@ return doc; | ||
} | ||
return docs.filter((doc) => patterns.some((filepath) => doc.source.name.includes(filepath))); | ||
return docs.filter(doc => patterns.some(filepath => doc.source.name.includes(filepath))); | ||
} | ||
const index = commands.createCommand((api) => { | ||
const index = commands.createCommand(api => { | ||
const { loaders } = api; | ||
@@ -120,2 +122,10 @@ return { | ||
}, | ||
maxAliasCount: { | ||
describe: 'Fail on operations with too many aliases', | ||
type: 'number', | ||
}, | ||
maxDirectiveCount: { | ||
describe: 'Fail on operations with too many directives', | ||
type: 'number', | ||
}, | ||
apollo: { | ||
@@ -170,3 +180,5 @@ describe: 'Support Apollo directives', | ||
const method = ((_a = args.method) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'POST'; | ||
const maxDepth = args.maxDepth || undefined; | ||
const maxDepth = args.maxDepth != null ? args.maxDepth : undefined; | ||
const maxAliasCount = args.maxAliasCount != null ? args.maxAliasCount : undefined; | ||
const maxDirectiveCount = args.maxDirectiveCount != null ? args.maxDirectiveCount : undefined; | ||
const strictFragments = !args.noStrictFragments; | ||
@@ -193,2 +205,4 @@ const keepClientFields = args.keepClientFields || false; | ||
maxDepth, | ||
maxAliasCount, | ||
maxDirectiveCount, | ||
strictFragments, | ||
@@ -209,4 +223,3 @@ keepClientFields, | ||
if (invalidDocuments.length) { | ||
return invalidDocuments.filter((doc) => doc.errors && doc.errors.length) | ||
.length; | ||
return invalidDocuments.filter(doc => doc.errors && doc.errors.length).length; | ||
} | ||
@@ -217,3 +230,3 @@ return 0; | ||
if (invalidDocuments.length) { | ||
return invalidDocuments.filter((doc) => doc.deprecated && doc.deprecated.length).length; | ||
return invalidDocuments.filter(doc => doc.deprecated && doc.deprecated.length).length; | ||
} | ||
@@ -226,5 +239,5 @@ return 0; | ||
} | ||
invalidDocuments.forEach((doc) => { | ||
invalidDocuments.forEach(doc => { | ||
if (doc.errors.length) { | ||
renderErrors(doc.source.name, doc[listKey], isError).forEach((line) => { | ||
renderErrors(doc.source.name, doc[listKey], isError).forEach(line => { | ||
logger.Logger.log(line); | ||
@@ -236,5 +249,3 @@ }); | ||
function renderErrors(sourceName, errors, isError = false) { | ||
const errorsAsString = errors | ||
.map((e) => ` - ${logger.bolderize(e.message)}`) | ||
.join('\n'); | ||
const errorsAsString = errors.map(e => ` - ${logger.bolderize(e.message)}`).join('\n'); | ||
return [ | ||
@@ -241,0 +252,0 @@ isError ? logger.chalk.redBright('error') : logger.chalk.yellowBright('warn'), |
{ | ||
"name": "@graphql-inspector/validate-command", | ||
"version": "0.0.0-canary.36985fe", | ||
"version": "0.0.0-canary.36b26d2", | ||
"description": "Validate Documents in GraphQL Inspector", | ||
"sideEffects": false, | ||
"peerDependencies": { | ||
"graphql": "^0.13.0 || ^14.0.0 || ^15.0.0" | ||
"graphql": "^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" | ||
}, | ||
"dependencies": { | ||
"@graphql-inspector/commands": "0.0.0-canary.36985fe", | ||
"@graphql-inspector/core": "0.0.0-canary.36985fe", | ||
"@graphql-inspector/logger": "0.0.0-canary.36985fe", | ||
"@graphql-inspector/commands": "0.0.0-canary.36b26d2", | ||
"@graphql-inspector/core": "0.0.0-canary.36b26d2", | ||
"@graphql-inspector/logger": "0.0.0-canary.36b26d2", | ||
"tslib": "^2.0.0" | ||
@@ -14,0 +14,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
21085
526
0
+ Added@graphql-inspector/commands@0.0.0-canary.36b26d2(transitive)
+ Added@graphql-inspector/config@0.0.0-canary.36b26d2(transitive)
+ Added@graphql-inspector/core@0.0.0-canary.36b26d2(transitive)
+ Added@graphql-inspector/loaders@0.0.0-canary.36b26d2(transitive)
+ Added@graphql-inspector/logger@0.0.0-canary.36b26d2(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedgraphql@16.9.0(transitive)
+ Addedyargs@17.2.1(transitive)
- Removed@graphql-inspector/commands@0.0.0-canary.36985fe(transitive)
- Removed@graphql-inspector/config@0.0.0-canary.36985fe(transitive)
- Removed@graphql-inspector/core@0.0.0-canary.36985fe(transitive)
- Removed@graphql-inspector/loaders@0.0.0-canary.36985fe(transitive)
- Removed@graphql-inspector/logger@0.0.0-canary.36985fe(transitive)
- Removedchalk@4.1.1(transitive)
- Removedgraphql@15.9.0(transitive)
- Removedyargs@17.1.1(transitive)