Skip to content

Commit

Permalink
order similar types by percentage (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
martyganz authored and kamilkisiela committed Nov 22, 2018
1 parent afd14b7 commit 4abb873
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions example/schemas/similar.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ type BlogPost {
id: ID
}

type MailPost {
title: String
createdAt: String
}

type EmailPost {
title: String
createdAt: String
modifiedAt: String
}

type Comment {
id: ID
}
Expand Down
4 changes: 2 additions & 2 deletions src/similar/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {printType, GraphQLNamedType, GraphQLSchema} from 'graphql';

import {isPrimitive, isForIntrospection} from '../utils/graphql';
import {findBestMatch, BestMatch, Target} from '../utils/string';
import {findBestMatch, BestMatch, Target, Rating} from '../utils/string';

export interface SimilarMap {
[name: string]: BestMatch;
Expand Down Expand Up @@ -64,7 +64,7 @@ function similarTo(
bestMatch: result.bestMatch,
ratings: result.ratings.filter(
r => r.rating >= threshold && r.target !== result.bestMatch.target,
),
).sort((a: Rating, b: Rating) => a.rating + b.rating),
};
}

Expand Down

0 comments on commit 4abb873

Please sign in to comment.