Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
strictDeprecated: boolean;
noStrictFragments: boolean;
apollo: boolean;
maxDepth: number;
}) => {
try {
const config = await loadProjectConfig({
extensions: [ValidateExtension]
});
const [schema, documents] = await Promise.all([
config.getSchema(),
config.getDocuments(),
]);
const results = validate(schema, documents.map(doc => new Source(print(doc.document), doc.location)), options);
for (const result of results) {
for (const error of result.errors) {
for (const location of error.locations) {
console.error(chalk.bold.underline(`${result.source.name}:${location.line}:${location.column};`));
console.error(` ` + chalk.red(`Error: ${error.message}`));
}
}
for (const error of result.deprecated) {
for (const location of error.locations) {
console.error(chalk.bold.underline(`${result.source.name}:${location.line}:${location.column};`));
console.error(` ` + chalk.red(`Error: ${error.message}`));
}
}
}
if (results.length === 0) {
console.info(`Documents are valid against the schema!`);
apollo?: boolean;
keepClientFields?: boolean;
maxDepth?: number;
renderer?: Renderer;
headers?: Record;
},
) {
const renderer = options.renderer || new ConsoleRenderer();
try {
const schema = await loadSchema(schemaPointer, {
headers: options.headers,
});
const documents = await loadDocuments(documentsPointer);
const invalidDocuments = validateDocuments(schema, documents, {
strictFragments: !options.noStrictFragments,
maxDepth: options.maxDepth || undefined,
apollo: options.apollo || false,
keepClientFields: options.keepClientFields || false,
});
if (!invalidDocuments.length) {
renderer.success('All documents are valid');
} else {
const errorsCount = countErrors(invalidDocuments);
const deprecated = countDeprecated(invalidDocuments);
if (errorsCount) {
renderer.emit(
`\nDetected ${errorsCount} invalid document${
errorsCount > 1 ? 's' : ''