Working With Promises
The Apollo API contains a few places that return a Promise:
- Calling the
mutate
function. - Calling
refetch
on a query result
In reason-react-apollo, these get typed using future, a Js.Promise
alternative written in ReasonML. They're also wrapped in a Belt.Result.t
type to account for the underlying JS Promise catching an error.
Future's README provides lots of excellent examples of how to work with its type using the built-in utlity functions, and these compose into some nice abstractions for working specifically with Apollo that may or may not get included in this library some day ๐.
Why use a third party library?
Because of the way promises were implemented in JavaScript, typing them (and working with them natively) in ReasonML is chanllenging. If you're curious, there are several discussions about why this is to be found in the Reason forums, or here's a pretty good overview of the problem.
The decision to include another dependency for this project wasn't taken lightly. It was made with an eye towards pushing the community to adopt a type-safe alternative to Js.Promise
that becomes a de facto standard for bindings libraries like this one (or at least until one is included in BuckleScript ๐).
All that said, if this is a deal-breaker for you, feel free to file an issue. The fact that most of this library's code gets generated for your project opens up the possibility of a config switch that would allow for a native Js.Promise API in the future.