Skip to content

Conversation

@jeong-sik
Copy link

@jeong-sik jeong-sik commented Jul 8, 2021

#116

Fixed an issue where objects could not be found due to unnecessary currying.

You can now properly use the forward function in ErrorLink

Now It Works

let errorLink: ApolloClient.Link.t = ApolloClient.Link.ErrorLink.make(handler => {
  // Todo forward, operation 처리
  let {networkError, graphQLErrors, operation, response, forward} = handler

  switch graphQLErrors {
  | Some(e') => e'->Array.map(v => v->handleGraphQLError)
  | None => [()]
  }->ignore

  switch networkError {
  | Some(networkError') => handleNetworkError(networkError')
  | None => ()
  }->ignore

  switch response {
  | Some(response') => Js.log2("Error Link response", response')
  | None => ()
  }->ignore

  let dict = Js.Dict.empty()
  let headers = Js.Dict.empty()
  headers->Js.Dict.set(
    "Authorization",
    "Bearer XXX",
  )
  dict->Js.Dict.set("headers", Obj.magic(headers)->Js.Json.object_)
  Js.log(dict)
  operation.setContext(Obj.magic(Obj.magic(dict)->Js.Json.object_))->ignore
  let link = forward(operation)
  Some(link)
})

Before

function fromJs(js) {
  return {
          graphQLErrors: js.graphQLErrors,
          networkError: Belt_Option.map(js.networkError, (function (networkError) {
                  var error = classify(networkError);
                  switch (error.TAG | 0) {
                    case /* Error */0 :
                        return {
                                TAG: /* FetchFailure */0,
                                _0: error._0
                              };
                    case /* ServerError */1 :
                        var error$1 = error._0;
                        return {
                                TAG: /* BadStatus */1,
                                _0: error$1.statusCode,
                                _1: error$1
                              };
                    case /* ServerParseError */2 :
                        return {
                                TAG: /* BadBody */2,
                                _0: error._0
                              };
                    
                  }
                })),
          response: js.response,
          operation: ApolloClient__Link_Core_Types.Operation.fromJs(js.operation),
          forward: (function (operation) {
              return Curry._1(js.forward(), operation);
            })
        };
}

After

function fromJs(js) {
  return {
          graphQLErrors: js.graphQLErrors,
          networkError: Belt_Option.map(js.networkError, (function (networkError) {
                  var error = classify(networkError);
                  switch (error.TAG | 0) {
                    case /* Error */0 :
                        return {
                                TAG: /* FetchFailure */0,
                                _0: error._0
                              };
                    case /* ServerError */1 :
                        var error$1 = error._0;
                        return {
                                TAG: /* BadStatus */1,
                                _0: error$1.statusCode,
                                _1: error$1
                              };
                    case /* ServerParseError */2 :
                        return {
                                TAG: /* BadBody */2,
                                _0: error._0
                              };
                    
                  }
                })),
          response: js.response,
          operation: ApolloClient__Link_Core_Types.Operation.fromJs(js.operation),
          forward: (function (operation) {
              return js.forward(operation);
            })
        };
}

Copy link
Owner

@jeddeloh jeddeloh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect. Thank you!

@jeddeloh jeddeloh merged commit c04a939 into jeddeloh:master Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants