forked from graphql/graphql-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into sogko/master
* master: (26 commits) 0.6.0 Validation: improving overlapping fields quality (graphql#386) Validation: context.getFragmentSpreads now accepts selectionSet rather than fragment AST node Factor out more closure functions Factor out closure functions to normal functions Deprecated directive (graphql#384) RFC: Directive location: schema definition (graphql#382) RFC: Schema Language Directives (graphql#376) Export introspection in public API Export directive definitions. (graphql#381) BUG: Ensure building AST schema does not exclude @Skip and @include (graphql#380) documentation of schema constructor Revert "Remove all 'instanceof GraphQLSchema' checks" (graphql#377) remove all 'instanceof GraphQLSchema' checks (graphql#371) Error logging for new interface type semantics (graphql#350) Nit: Missing case in grammar for TypeSystemDefinition in comment Bug: printer can print non-parsable value Factor out suggestion quoting utility Minor refactoring Minor refactoring of error messages for unknown fields ...
- Loading branch information
Showing
39 changed files
with
2,121 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "graphql", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "A Query Language and Runtime which can target any service.", | ||
"contributors": [ | ||
"Lee Byron <[email protected]> (http://leebyron.com/)", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
import quotedOrList from '../quotedOrList'; | ||
|
||
describe('quotedOrList', () => { | ||
|
||
it('Does not accept an empty list', () => { | ||
expect(() => quotedOrList([])).to.throw(TypeError); | ||
}); | ||
|
||
it('Returns single quoted item', () => { | ||
expect(quotedOrList([ 'A' ])).to.equal('"A"'); | ||
}); | ||
|
||
it('Returns two item list', () => { | ||
expect(quotedOrList([ 'A', 'B' ])).to.equal('"A" or "B"'); | ||
}); | ||
|
||
it('Returns comma separated many item list', () => { | ||
expect(quotedOrList([ 'A', 'B', 'C' ])).to.equal('"A", "B", or "C"'); | ||
}); | ||
|
||
it('Limits to five items', () => { | ||
expect( | ||
quotedOrList([ 'A', 'B', 'C', 'D', 'E', 'F' ]) | ||
).to.equal( | ||
'"A", "B", "C", "D", or "E"' | ||
); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
import suggestionList from '../suggestionList'; | ||
|
||
describe('suggestionList', () => { | ||
|
||
it('Returns results when input is empty', () => { | ||
expect(suggestionList('', [ 'a' ])).to.deep.equal([ 'a' ]); | ||
}); | ||
|
||
it('Returns empty array when there are no options', () => { | ||
expect(suggestionList('input', [])).to.deep.equal([]); | ||
}); | ||
|
||
it('Returns options sorted based on similarity', () => { | ||
expect(suggestionList('abc', [ 'a', 'ab', 'abc' ])) | ||
.to.deep.equal([ 'abc', 'ab' ]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* @flow */ | ||
/** | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
const MAX_LENGTH = 5; | ||
|
||
/** | ||
* Given [ A, B, C ] return '"A", "B", or "C"'. | ||
*/ | ||
export default function quotedOrList(items: Array<string>): string { | ||
const selected = items.slice(0, MAX_LENGTH); | ||
return selected | ||
.map(item => `"${item}"`) | ||
.reduce((list, quoted, index) => | ||
list + | ||
(selected.length > 2 ? ', ' : ' ') + | ||
(index === selected.length - 1 ? 'or ' : '') + | ||
quoted | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* @flow */ | ||
/** | ||
* Copyright (c) 2015, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
/** | ||
* Given an invalid input string and a list of valid options, returns a filtered | ||
* list of valid options sorted based on their similarity with the input. | ||
*/ | ||
export default function suggestionList( | ||
input: string, | ||
options: Array<string> | ||
): Array<string> { | ||
const optionsByDistance = Object.create(null); | ||
const oLength = options.length; | ||
const inputThreshold = input.length / 2; | ||
for (let i = 0; i < oLength; i++) { | ||
const distance = lexicalDistance(input, options[i]); | ||
const threshold = Math.max(inputThreshold, options[i].length / 2, 1); | ||
if (distance <= threshold) { | ||
optionsByDistance[options[i]] = distance; | ||
} | ||
} | ||
return Object.keys(optionsByDistance).sort( | ||
(a , b) => optionsByDistance[a] - optionsByDistance[b] | ||
); | ||
} | ||
|
||
/** | ||
* Computes the lexical distance between strings A and B. | ||
* | ||
* The "distance" between two strings is given by counting the minimum number | ||
* of edits needed to transform string A into string B. An edit can be an | ||
* insertion, deletion, or substitution of a single character, or a swap of two | ||
* adjacent characters. | ||
* | ||
* This distance can be useful for detecting typos in input or sorting | ||
* | ||
* @param {string} a | ||
* @param {string} b | ||
* @return {int} distance in number of edits | ||
*/ | ||
function lexicalDistance(a, b) { | ||
let i; | ||
let j; | ||
const d = []; | ||
const aLength = a.length; | ||
const bLength = b.length; | ||
|
||
for (i = 0; i <= aLength; i++) { | ||
d[i] = [ i ]; | ||
} | ||
|
||
for (j = 1; j <= bLength; j++) { | ||
d[0][j] = j; | ||
} | ||
|
||
for (i = 1; i <= aLength; i++) { | ||
for (j = 1; j <= bLength; j++) { | ||
const cost = a[i - 1] === b[j - 1] ? 0 : 1; | ||
|
||
d[i][j] = Math.min( | ||
d[i - 1][j] + 1, | ||
d[i][j - 1] + 1, | ||
d[i - 1][j - 1] + cost | ||
); | ||
|
||
if (i > 1 && j > 1 && | ||
a[i - 1] === b[j - 2] && | ||
a[i - 2] === b[j - 1]) { | ||
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + cost); | ||
} | ||
} | ||
} | ||
|
||
return d[aLength][bLength]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.