Skip to content

v1.0.0-beta.0

Choose a tag to compare

@jeddeloh jeddeloh released this 16 Oct 13:35
· 151 commits to master since this release
5d5614b

Breaking Changes

  • Methods are now located directly on the record. Previously, they were functions in the type modules.
  • graphql-ppx parse 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 result if they can fail.
  • Improved return values of promises (Ok definitely has some form of data, and all other cases are moved to the Error variant)
  • ApolloError.t is used exclusively across the library instead of say errors: array(GraphQLError.t). This allows us to express more types of errors, like a parse failure mentioned above.

Features

  • Added readFragment methods

Bug Fixes

  • Fixed NetworkStatus bindings
  • Fixed some methods still expecting graphql-ppx Raw.t_variables instead t_variables
  • Made variables on refetch optional

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.