Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
options: {
require?: string[];
headers?: Record;
write?: string;
renderer?: Renderer;
},
) {
const renderer = options.renderer || new ConsoleRenderer();
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));
.action(async (options: {
type: string;
threshold: number;
write: string;
}) => {
try {
const config = await loadProjectConfig({
extensions: [SimilarExtension]
});
const schema = await config.getSchema();
const results = similar(schema, options.type, options.threshold);
for (const key in results) {
const result = results[key];
if (result.ratings.length > 0) {
console.info(chalk.bold.underline(key) + ':');
for (const rating of result.ratings) {
console.info(` ` + rating.target.typeId + ': ' + colorizePercentage(rating.rating * 100));
}
}
}
if (options.write) {
writeFileSync(join(process.cwd(), options.write), JSON.stringify(results, null, 2));
}
} catch (e) {
reportError(e);
}
});