Created
April 3, 2018 07:09
-
-
Save ca057/4c2abb4768719ff8d710ed0933f1ae1c to your computer and use it in GitHub Desktop.
Apollo HOF to conditionally resolve with an empty list
This file contains hidden or 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
/** | |
* Curried higher-order function taking a predicate and an actual resolver function. In case the | |
* predicate returns true, an empty list is returned, otherwise the result of the actual resolver function. | |
* | |
* Both the predicate and the resolver function will get the all arguments as a standard resolver function. | |
*/ | |
const condResolveEmptyList = predicate => resolver => ( | |
data, | |
args, | |
context, | |
info | |
) => { | |
if (predicate(data, args, context, info)) return []; | |
return resolver(data, args, context, info); | |
}; | |
module.exports = { | |
condResolveEmptyList, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment