@graphql-inspector/validate-command
Advanced tools
Comparing version 0.0.0-canary.8127707 to 0.0.0-canary.0fd8c6a
106
index.cjs.js
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
const tslib = require('tslib'); | ||
@@ -9,3 +11,45 @@ const commands = require('@graphql-inspector/commands'); | ||
function handler({ schema, documents, strictFragments, maxDepth, apollo, keepClientFields, failOnDeprecated, }) { | ||
const invalidDocuments = core.validate(schema, documents.map((doc) => new graphql.Source(graphql.print(doc.document), doc.location)), { | ||
strictFragments, | ||
maxDepth, | ||
apollo, | ||
keepClientFields, | ||
}); | ||
if (!invalidDocuments.length) { | ||
logger.Logger.success('All documents are valid'); | ||
} | ||
else { | ||
const errorsCount = countErrors(invalidDocuments); | ||
const deprecated = countDeprecated(invalidDocuments); | ||
if (errorsCount) { | ||
logger.Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`); | ||
invalidDocuments.forEach((doc) => { | ||
if (doc.errors.length) { | ||
renderInvalidDocument(doc).forEach((line) => { | ||
logger.Logger.log(line); | ||
}); | ||
} | ||
}); | ||
} | ||
else if (!failOnDeprecated) { | ||
logger.Logger.success('All documents are valid'); | ||
} | ||
if (deprecated) { | ||
logger.Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`); | ||
invalidDocuments.forEach((doc) => { | ||
if (doc.deprecated.length) { | ||
renderDeprecatedUsageInDocument(doc, failOnDeprecated).forEach((line) => { | ||
logger.Logger.log(line); | ||
}); | ||
} | ||
}); | ||
} | ||
if (errorsCount || (deprecated && failOnDeprecated)) { | ||
process.exit(1); | ||
} | ||
} | ||
} | ||
const index = commands.createCommand((api) => { | ||
const { loaders } = api; | ||
return { | ||
@@ -27,4 +71,4 @@ command: 'validate <documents> <schema>', | ||
.options({ | ||
d: { | ||
alias: 'deprecated', | ||
deprecated: { | ||
alias: 'd', | ||
describe: 'Fail on deprecated usage', | ||
@@ -57,7 +101,8 @@ type: 'boolean', | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
const { loaders, intercept } = api; | ||
if (intercept) { | ||
intercept(args); | ||
} | ||
const { headers, token } = commands.parseGlobalArgs(args); | ||
const apollo = args.apollo || false; | ||
const maxDepth = args.maxDepth || undefined; | ||
const strictFragments = !args.noStrictFragments; | ||
const keepClientFields = args.keepClientFields || false; | ||
const failOnDeprecated = args.deprecated; | ||
const schema = yield loaders.loadSchema(args.schema, { | ||
@@ -68,41 +113,11 @@ headers, | ||
const documents = yield loaders.loadDocuments(args.documents); | ||
const invalidDocuments = core.validate(schema, documents.map((doc) => new graphql.Source(graphql.print(doc.document), doc.location)), { | ||
strictFragments: !args.noStrictFragments, | ||
maxDepth: args.maxDepth || undefined, | ||
apollo: args.apollo || false, | ||
keepClientFields: args.keepClientFields || false, | ||
return handler({ | ||
schema, | ||
documents, | ||
apollo, | ||
maxDepth, | ||
strictFragments, | ||
keepClientFields, | ||
failOnDeprecated, | ||
}); | ||
if (!invalidDocuments.length) { | ||
logger.Logger.success('All documents are valid'); | ||
} | ||
else { | ||
const errorsCount = countErrors(invalidDocuments); | ||
const deprecated = countDeprecated(invalidDocuments); | ||
if (errorsCount) { | ||
logger.Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`); | ||
invalidDocuments.forEach((doc) => { | ||
if (doc.errors.length) { | ||
renderInvalidDocument(doc).forEach((line) => { | ||
logger.Logger.log(line); | ||
}); | ||
} | ||
}); | ||
} | ||
else if (!args.deprecated) { | ||
logger.Logger.success('All documents are valid'); | ||
} | ||
if (deprecated) { | ||
logger.Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`); | ||
invalidDocuments.forEach((doc) => { | ||
if (doc.deprecated.length) { | ||
renderDeprecatedUsageInDocument(doc, args.deprecated).forEach((line) => { | ||
logger.Logger.log(line); | ||
}); | ||
} | ||
}); | ||
} | ||
if (errorsCount || (deprecated && args.deprecated)) { | ||
process.exit(1); | ||
} | ||
} | ||
}); | ||
@@ -148,3 +163,4 @@ }, | ||
module.exports = index; | ||
exports.default = index; | ||
exports.handler = handler; | ||
//# sourceMappingURL=index.cjs.js.map |
@@ -1,11 +0,23 @@ | ||
import { GlobalArgs } from '@graphql-inspector/commands'; | ||
declare const _default: import("../../commands/src").CommandFactory<{}, { | ||
import { GlobalArgs, CommandFactory } from '@graphql-inspector/commands'; | ||
import { Source as DocumentSource } from '@graphql-tools/utils'; | ||
import { GraphQLSchema } from 'graphql'; | ||
export { CommandFactory }; | ||
export declare function handler({ schema, documents, strictFragments, maxDepth, apollo, keepClientFields, failOnDeprecated, }: { | ||
schema: GraphQLSchema; | ||
documents: DocumentSource[]; | ||
failOnDeprecated: boolean; | ||
strictFragments: boolean; | ||
apollo: boolean; | ||
keepClientFields: boolean; | ||
maxDepth?: number; | ||
}): void; | ||
declare const _default: CommandFactory<{}, { | ||
schema: string; | ||
documents: string; | ||
deprecated?: boolean | undefined; | ||
deprecated: boolean; | ||
noStrictFragments: boolean; | ||
apollo?: boolean | undefined; | ||
keepClientFields?: boolean | undefined; | ||
apollo: boolean; | ||
keepClientFields: boolean; | ||
maxDepth?: number | undefined; | ||
} & GlobalArgs>; | ||
export default _default; |
102
index.esm.js
@@ -7,3 +7,45 @@ import { __awaiter } from 'tslib'; | ||
function handler({ schema, documents, strictFragments, maxDepth, apollo, keepClientFields, failOnDeprecated, }) { | ||
const invalidDocuments = validate(schema, documents.map((doc) => new Source(print(doc.document), doc.location)), { | ||
strictFragments, | ||
maxDepth, | ||
apollo, | ||
keepClientFields, | ||
}); | ||
if (!invalidDocuments.length) { | ||
Logger.success('All documents are valid'); | ||
} | ||
else { | ||
const errorsCount = countErrors(invalidDocuments); | ||
const deprecated = countDeprecated(invalidDocuments); | ||
if (errorsCount) { | ||
Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`); | ||
invalidDocuments.forEach((doc) => { | ||
if (doc.errors.length) { | ||
renderInvalidDocument(doc).forEach((line) => { | ||
Logger.log(line); | ||
}); | ||
} | ||
}); | ||
} | ||
else if (!failOnDeprecated) { | ||
Logger.success('All documents are valid'); | ||
} | ||
if (deprecated) { | ||
Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`); | ||
invalidDocuments.forEach((doc) => { | ||
if (doc.deprecated.length) { | ||
renderDeprecatedUsageInDocument(doc, failOnDeprecated).forEach((line) => { | ||
Logger.log(line); | ||
}); | ||
} | ||
}); | ||
} | ||
if (errorsCount || (deprecated && failOnDeprecated)) { | ||
process.exit(1); | ||
} | ||
} | ||
} | ||
const index = createCommand((api) => { | ||
const { loaders } = api; | ||
return { | ||
@@ -25,4 +67,4 @@ command: 'validate <documents> <schema>', | ||
.options({ | ||
d: { | ||
alias: 'deprecated', | ||
deprecated: { | ||
alias: 'd', | ||
describe: 'Fail on deprecated usage', | ||
@@ -55,7 +97,8 @@ type: 'boolean', | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { loaders, intercept } = api; | ||
if (intercept) { | ||
intercept(args); | ||
} | ||
const { headers, token } = parseGlobalArgs(args); | ||
const apollo = args.apollo || false; | ||
const maxDepth = args.maxDepth || undefined; | ||
const strictFragments = !args.noStrictFragments; | ||
const keepClientFields = args.keepClientFields || false; | ||
const failOnDeprecated = args.deprecated; | ||
const schema = yield loaders.loadSchema(args.schema, { | ||
@@ -66,41 +109,11 @@ headers, | ||
const documents = yield loaders.loadDocuments(args.documents); | ||
const invalidDocuments = validate(schema, documents.map((doc) => new Source(print(doc.document), doc.location)), { | ||
strictFragments: !args.noStrictFragments, | ||
maxDepth: args.maxDepth || undefined, | ||
apollo: args.apollo || false, | ||
keepClientFields: args.keepClientFields || false, | ||
return handler({ | ||
schema, | ||
documents, | ||
apollo, | ||
maxDepth, | ||
strictFragments, | ||
keepClientFields, | ||
failOnDeprecated, | ||
}); | ||
if (!invalidDocuments.length) { | ||
Logger.success('All documents are valid'); | ||
} | ||
else { | ||
const errorsCount = countErrors(invalidDocuments); | ||
const deprecated = countDeprecated(invalidDocuments); | ||
if (errorsCount) { | ||
Logger.log(`\nDetected ${errorsCount} invalid document${errorsCount > 1 ? 's' : ''}:\n`); | ||
invalidDocuments.forEach((doc) => { | ||
if (doc.errors.length) { | ||
renderInvalidDocument(doc).forEach((line) => { | ||
Logger.log(line); | ||
}); | ||
} | ||
}); | ||
} | ||
else if (!args.deprecated) { | ||
Logger.success('All documents are valid'); | ||
} | ||
if (deprecated) { | ||
Logger.info(`\nDetected ${deprecated} document${deprecated > 1 ? 's' : ''} with deprecated fields:\n`); | ||
invalidDocuments.forEach((doc) => { | ||
if (doc.deprecated.length) { | ||
renderDeprecatedUsageInDocument(doc, args.deprecated).forEach((line) => { | ||
Logger.log(line); | ||
}); | ||
} | ||
}); | ||
} | ||
if (errorsCount || (deprecated && args.deprecated)) { | ||
process.exit(1); | ||
} | ||
} | ||
}); | ||
@@ -147,2 +160,3 @@ }, | ||
export default index; | ||
export { handler }; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@graphql-inspector/validate-command", | ||
"version": "0.0.0-canary.8127707", | ||
"version": "0.0.0-canary.0fd8c6a", | ||
"description": "Validate Documents in GraphQL Inspector", | ||
@@ -10,5 +10,5 @@ "sideEffects": false, | ||
"dependencies": { | ||
"@graphql-inspector/commands": "0.0.0-canary.8127707", | ||
"@graphql-inspector/core": "0.0.0-canary.8127707", | ||
"@graphql-inspector/logger": "0.0.0-canary.8127707", | ||
"@graphql-inspector/commands": "0.0.0-canary.0fd8c6a", | ||
"@graphql-inspector/core": "0.0.0-canary.0fd8c6a", | ||
"@graphql-inspector/logger": "0.0.0-canary.0fd8c6a", | ||
"tslib": "^2.0.0" | ||
@@ -15,0 +15,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
35262
335
+ Added@graphql-inspector/commands@0.0.0-canary.0fd8c6a(transitive)
+ Added@graphql-inspector/config@0.0.0-canary.0fd8c6a(transitive)
+ Added@graphql-inspector/core@0.0.0-canary.0fd8c6a(transitive)
+ Added@graphql-inspector/loaders@0.0.0-canary.0fd8c6a(transitive)
+ Added@graphql-inspector/logger@0.0.0-canary.0fd8c6a(transitive)
- Removed@graphql-inspector/commands@0.0.0-canary.8127707(transitive)
- Removed@graphql-inspector/config@0.0.0-canary.8127707(transitive)
- Removed@graphql-inspector/core@0.0.0-canary.8127707(transitive)
- Removed@graphql-inspector/loaders@0.0.0-canary.8127707(transitive)
- Removed@graphql-inspector/logger@0.0.0-canary.8127707(transitive)