jeddeloh / rescript-apollo-client

ReScript bindings for the Apollo Client ecosystem
MIT License
126 stars 18 forks source link

Bug in ensureApolloError #96

Closed maarekj closed 3 years ago

maarekj commented 3 years ago

Since the commit 8508e946e113a772c75cc65360cd285b9f43dbf1 there is a bug in function ensureApolloError

This function is declared like this:

  let ensureApolloError: t => t = error =>
    %bs.raw(`
          function (error, makeApolloError) {
            var error = error || {};
            if (Array.isArray(error.graphQLErrors)) {
              return error;
            } else if (error && typeof error.message === "string" && error.extensions) {
              return makeApolloError({graphQLErrors: [error]});
            } else {
              return makeApolloError({networkError: ensureError(error)}) 
            }
          }
        `)(error, make, ensureError)

The raw function takes 2 parameters in input, and it is called with 3 parameters.

I think in fix it, we need to do this:

  let ensureApolloError: t => t = error =>
    %bs.raw(`
          function (error, makeApolloError, ensureError) {
            var error = error || {};
            if (Array.isArray(error.graphQLErrors)) {
              return error;
            } else if (error && typeof error.message === "string" && error.extensions) {
              return makeApolloError({graphQLErrors: [error]});
            } else {
              return makeApolloError({networkError: ensureError(error)}) 
            }
          }
        `)(error, make, ensureError)
jeddeloh commented 3 years ago

Excellent, thanks! Sadly, there is a unit test for this that was failing, but I never hooked them up to run in github actions. :(

jeddeloh commented 3 years ago

This is released in 1.1.1