-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(onUnhandled*): The call feature for unhandled paths.
Updated the call version of the algorithm to handle the function does not exist error. If there is an error and its CallNotFoundError then we will chain. I also updated the interface to be the agreed upon interface of a DataSource.
- Loading branch information
1 parent
64f47b3
commit 2532999
Showing
20 changed files
with
252 additions
and
275 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
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,8 @@ | ||
var MESSAGE = 'function does not exist.'; | ||
var CallNotFoundError = module.exports = function CallNotFoundError() { | ||
this.message = MESSAGE; | ||
this.stack = (new Error()).stack; | ||
}; | ||
|
||
CallNotFoundError.prototype = new Error(); | ||
|
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,9 @@ | ||
var MESSAGE = 'Any JSONG-Graph returned from call must have paths.'; | ||
var CallRequiresPathsError = function CallRequiresPathsError() { | ||
this.message = MESSAGE; | ||
this.stack = (new Error()).stack; | ||
}; | ||
|
||
CallRequiresPathsError.prototype = new Error(); | ||
|
||
module.exports = CallRequiresPathsError; |
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,66 @@ | ||
var call = 'call'; | ||
var runCallAction = require('./../run/call/runCallAction'); | ||
var recurseMatchAndExecute = require('./../run/recurseMatchAndExecute'); | ||
var normalizePathSets = require('../operations/ranges/normalizePathSets'); | ||
var CallNotFoundError = require('./../errors/CallNotFoundError'); | ||
var materialize = require('../run/materialize'); | ||
var pathUtils = require('falcor-path-utils'); | ||
var collapse = pathUtils.collapse; | ||
|
||
/** | ||
* Performs the call mutation. If a call is unhandled, IE throws error, then | ||
* we will chain to the next dataSource in the line. | ||
*/ | ||
module.exports = function routerCall(callPath, args, | ||
refPathsArg, thisPathsArg) { | ||
var refPaths = normalizePathSets(refPathsArg || []); | ||
var thisPaths = normalizePathSets(thisPathsArg || []); | ||
|
||
var jsongCache = {}; | ||
var router = this; | ||
var action = runCallAction(router, callPath, args, | ||
refPaths, thisPaths, jsongCache); | ||
var callPaths = [callPath]; | ||
return recurseMatchAndExecute(router._matcher, action, callPaths, call, | ||
router, jsongCache). | ||
|
||
// Take that | ||
map(function(jsongResult) { | ||
var reportedPaths = jsongResult.reportedPaths; | ||
var jsongEnv = { | ||
jsonGraph: jsongResult.jsonGraph | ||
}; | ||
|
||
// Call must report the paths that have been produced. | ||
if (reportedPaths.length) { | ||
// Collapse the reported paths as they may be inefficient | ||
// to send across the wire. | ||
jsongEnv.paths = collapse(reportedPaths); | ||
} | ||
else { | ||
jsongEnv.paths = []; | ||
jsongEnv.jsonGraph = {}; | ||
} | ||
|
||
// add the invalidated paths to the jsonGraph Envelope | ||
var invalidated = jsongResult.invalidated; | ||
if (invalidated && invalidated.length) { | ||
jsongEnv.invalidated = invalidated; | ||
} | ||
|
||
// Calls are currently materialized. | ||
materialize(router, reportedPaths, jsongEnv); | ||
return jsongEnv; | ||
}). | ||
|
||
// For us to be able to chain call requests then the error that is | ||
// caught has to be a 'function does not exist.' error. From that we | ||
// will try the next dataSource in the line. | ||
catch(function catchException(e) { | ||
if (e instanceof CallNotFoundError && router._unhandled) { | ||
return router._unhandled. | ||
call(callPath, args, refPaths, thisPaths); | ||
} | ||
throw 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
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
Oops, something went wrong.