-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jsutils: Add generic Path implementation (#2053)
- Loading branch information
1 parent
dae9f87
commit 52820eb
Showing
7 changed files
with
54 additions
and
66 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
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,11 +1,8 @@ | ||
// @flow strict | ||
|
||
export { | ||
execute, | ||
defaultFieldResolver, | ||
defaultTypeResolver, | ||
responsePathAsArray, | ||
} from './execute'; | ||
export { pathToArray as responsePathAsArray } from '../jsutils/Path'; | ||
|
||
export { execute, defaultFieldResolver, defaultTypeResolver } from './execute'; | ||
export type { ExecutionArgs, ExecutionResult } from './execute'; | ||
|
||
export { getDirectiveValues } from './values'; |
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 strict | ||
|
||
export type Path = {| | ||
+prev: Path | void, | ||
+key: string | number, | ||
|}; | ||
|
||
/** | ||
* Given a Path and a key, return a new Path containing the new key. | ||
*/ | ||
export function addPath(prev: $ReadOnly<Path> | void, key: string | number) { | ||
return { prev, key }; | ||
} | ||
|
||
/** | ||
* Given a Path, return an Array of the path keys. | ||
*/ | ||
export function pathToArray(path: $ReadOnly<Path>): Array<string | number> { | ||
const flattened = []; | ||
let curr = path; | ||
while (curr) { | ||
flattened.push(curr.key); | ||
curr = curr.prev; | ||
} | ||
return flattened.reverse(); | ||
} |
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