Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const writePath = options.write;
const shouldWrite = typeof writePath !== 'undefined';
try {
const schema = await loadSchema(schemaPointer, {
headers: options.headers,
});
const similarMap = findSimilar(schema, name, threshold);
if (!Object.keys(similarMap).length) {
renderer.emit('No similar types found');
} else {
for (const typeName in similarMap) {
if (similarMap.hasOwnProperty(typeName)) {
const matches = similarMap[typeName];
const prefix = getTypePrefix(schema.getType(
typeName,
) as GraphQLNamedType);
const sourceType = chalk.bold(typeName);
const name = matches.bestMatch.target.typeId;
renderer.emit();
renderer.emit(`${prefix} ${sourceType}`);
renderer.emit(printResult(name, matches.bestMatch.rating));
matches.ratings.forEach(match => {
renderer.emit(printResult(match.target.typeId, match.rating));
});
}
}
if (shouldWrite) {
coverage(coverage: SchemaCoverage) {
this.success('Schema coverage based on documents:\n');
for (const typeName in coverage.types) {
if (coverage.types.hasOwnProperty(typeName)) {
const typeCoverage = coverage.types[typeName];
this.emit(
chalk.grey(getTypePrefix(typeCoverage.type)),
chalk.bold(`${typeName}`),
chalk.grey('{'),
);
for (const childName in typeCoverage.children) {
if (typeCoverage.children.hasOwnProperty(childName)) {
const childCoverage = typeCoverage.children[childName];
if (childCoverage.hits) {
this.emit(
indent(childName, 2),
chalk.italic.grey(`x ${childCoverage.hits}`),
);
} else {
this.emit(
chalk.redBright(indent(childName, 2)),