Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a map fn for Graphqelm.Http.Error #52

Closed
sporto opened this issue Mar 22, 2018 · 0 comments
Closed

Add a map fn for Graphqelm.Http.Error #52

sporto opened this issue Mar 22, 2018 · 0 comments

Comments

@sporto
Copy link
Collaborator

sporto commented Mar 22, 2018

Version 11 made Graphqelm.Http.Error to be different types. So something like this is not possible anymore:

type Msg 
     = MonkeyFetched (Result Grapheqlm.Http.Error  Monkey)
     | MonkeyCreated (Result Grapheqlm.Http.Error CreateMonkeyMutationResponse)

case msg of

    MonkeyFetched result ->
        case result of
            Err err ->
                ({model | monkey = Failure err})    
            ....

    MonkeyCreated result ->
        case result of
            Err err ->
                ({model | monkey = Failure err})    

In the above case it make sense to treat the fetch and creation in a similar way. Having the error being different types prevents this from compiling.

The error type needs to be homogenised first e.g.

mapGraphelmError : (a -> b) -> Graphqelm.Http.Error a -> Graphqelm.Http.Error b
mapGraphelmError fn error =
    case error of 
         Graphqelm.Http.HttpError e ->
            Graphqelm.Http.HttpError e

         Graphqelm.Http.GraphqlError parsedData errors ->
            case parsedData of
                Graphqelm.Http.GraphqlError.ParsedData parsed ->
                     Graphqelm.Http.GraphqlError (Graphqelm.Http.GraphqlError.ParsedData (fn parsed)) errors
                
                Graphqelm.Http.GraphqlError.UnparsedData v ->
                     Graphqelm.Http.GraphqlError (Graphqelm.Http.GraphqlError.UnparsedData v) errors

And then

type Msg 
     = MonkeyFetched (Result (Grapheqlm.Http.Error (Maybe Monkey)) (Maybe Monkey))
     | MonkeyCreated (Result (Grapheqlm.Http.Error CreateMonkeyMutationResponse) CreateMonkeyMutationResponse)

MonkeyCreated result ->
            case result of
                Err mutationErr ->
                    let
                        err =
                            mapGraphelmError
                                (always Nothing)
                                mutationErr
                    in
                        ( { model | data = RemoteData.Failure err }
                        , ...
                        )

So, consider adding a mapError function unless there is better solution.

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

No branches or pull requests

1 participant