v1.0.0-beta.0
Breaking Changes
- Methods are now located directly on the record. Previously, they were functions in the type modules.
graphql-ppxparse functions are now safely wrapped so they return a result instead of allowing exceptions to escape the library (this is mostly transparent change because they are usually unwrapped at some point into an ApolloError if necessary).- Promise returning methods changed to return a
resultif they can fail. - Improved return values of promises (
Okdefinitely has some form of data, and all other cases are moved to theErrorvariant) ApolloError.tis used exclusively across the library instead of sayerrors: array(GraphQLError.t). This allows us to express more types of errors, like a parse failure mentioned above.
Features
- Added
readFragmentmethods
Bug Fixes
- Fixed
NetworkStatusbindings - Fixed some methods still expecting
graphql-ppxRaw.t_variablesinsteadt_variables - Made variables on
refetchoptional
Overview
Just like JavaScript!
Methods are now called directly from records or destructured. This should make for an easier transition for anyone coming from JavaScript as well as make things more discoverable and consistent.
let queryResult = TodosQuery.use();
<div>
{switch (queryResult) {
| {loading, data, error, fetchMore} =>
...Improved promise return values
Promises now return a result and will not reject. However, it's very common to forget to check for graphql errors when you're presented with an Ok/Error result. For this reason we're now a little smarter and we unwrap the case where you definitely have data, and everything else into error:
client.query(~query=(module TodosQuery), ())
|> Js.Promise.then_(result =>
switch (result) {
| Ok({data: {todos}, error: None}) =>
// You can't be Ok with data: None
| Ok({data: {todos}, error: Some(error)}) =>
// You _can_ have data and error, but only if you change error policy from default to "all"
| Error(error) =>
// Any other case is an error:
// - 200 response with graphqlErrors and no data (always if errorPolicy is "none", the default)
// - fetch error, etc.
// - no data and no error (impossible?)
}
);Parsing will no longer raise exceptions (mostly transparent change)
All parse functions now safely converted to result returning functions. For the vast majority of cases, Apollo returns a "result" of some type anyway so we unwrap the result and convert to an appropriate error representation. There are a few cases where this is not possible (like parsing previous values from the cache) so you have to deal with a result but I think in the end this is a good tradeoff.