Skip to content

Commit 4c10844

Browse files
committed
suggestionList: change threshold to be cofficient of input length
Steal idea from TypeScript compiler: https://github.com/microsoft/TypeScript/blob/afddaf090ad8e3a4d3501ce91490b5552d1e4a42/src/compiler/core.ts#L1752
1 parent e545162 commit 4c10844

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

src/jsutils/__tests__/suggestionList-test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ describe('suggestionList', () => {
5252
});
5353

5454
it('Returns options sorted based on lexical distance', () => {
55-
expectSuggestions('abc', ['a', 'ab', 'abc']).to.deep.equal(['abc', 'ab']);
55+
expectSuggestions('abc', ['a', 'ab', 'abc']).to.deep.equal([
56+
'abc',
57+
'ab',
58+
'a',
59+
]);
5660
});
5761

5862
it('Returns options with the same lexical distance sorted lexicographically', () => {

src/jsutils/suggestionList.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ export default function suggestionList(
1111
const optionsByDistance = Object.create(null);
1212
const lexicalDistance = new LexicalDistance(input);
1313

14-
const inputThreshold = input.length / 2;
14+
const threshold = Math.floor(input.length * 0.4) + 1;
1515
for (const option of options) {
16-
const threshold = Math.max(inputThreshold, option.length / 2, 1) | 0;
1716
const distance = lexicalDistance.measure(option, threshold);
1817
if (distance !== undefined) {
1918
optionsByDistance[option] = distance;

src/type/__tests__/enumType-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ describe('Type System: Enum Values', () => {
178178
errors: [
179179
{
180180
message:
181-
'Value "green" does not exist in "Color" enum. Did you mean the enum value "GREEN"?',
181+
'Value "green" does not exist in "Color" enum. Did you mean the enum value "GREEN" or "RED"?',
182182
locations: [{ line: 1, column: 23 }],
183183
},
184184
],

src/validation/__tests__/ValuesOfCorrectTypeRule-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -923,14 +923,14 @@ describe('Validate: Values of correct type', () => {
923923
complicatedArgs {
924924
complexArgField(complexArg: {
925925
requiredField: true,
926-
unknownField: "value"
926+
invalidField: "value"
927927
})
928928
}
929929
}
930930
`).to.deep.equal([
931931
{
932932
message:
933-
'Field "unknownField" is not defined by type "ComplexInput". Did you mean "booleanField", "intField", or "nonNullField"?',
933+
'Field "invalidField" is not defined by type "ComplexInput". Did you mean "intField"?',
934934
locations: [{ line: 6, column: 15 }],
935935
},
936936
]);

0 commit comments

Comments
 (0)