-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
HTTP interface doesn't handle errors correctly #48
Comments
Hey @xtian thanks for opening the issue. I thought about this when I wrote that code, but somehow it didn't seem like the obvious choice to ignore the data whenever an error occurs unconditionally, or to return both errors and data. Now that I think about it more, I think that maybe having multiple functions to handle these different strategies would be a good idea. Apollo Client has a similar approach. They allow you to configure Apollo's error handling strategy so that when there is both success data and > 0 errors in the response, you can choose to have it:
For example, the -- Function for option 2
-- This would be the default that most people would use and it would behave as you might expect
send : (Result Error decodesTo -> msg) -> Request decodesTo -> Cmd msg -- Function for option 1
sendIgnoreErrorIfHasData : (Result Error decodesTo -> msg) -> Request decodesTo -> Cmd msg -- Function for option 3
sendIncludeErrorsIfHasData :
(Result Error ( decodesTo, List GraphqlError ) -> msg)
-> Request decodesTo
-> Cmd msg Maybe these names could be more concise or expressive, but something like that. Another approach would be to have a union type to say which kind of request you want to make explicitly, but I think I like the idea of encouraging the best practice (and obvious behavior) without confusing configuration options, and then exposing the less common options if you need them so I think I prefer having separate functions as above. I also like that this multiple functions approach doesn't clutter up the return types by having this error data that you can forget to check if you want it to just fail if there were errors. What do you think of the multiple functions approach? |
I think that's a great idea! Would definitely work for our use-case |
Great! That feels like the right direction to me as well. I wonder if it should be a major version bump? Because in a way this could be considered a breaking change. |
@xtian I'm thinking about merging these strategies into one. I've implemented this on master and I think this gives us the benefits of all of them pretty well. In a nutshell,
I like this strategy because it always allows you to use the data when there is an error if you'd like to (or see it for debugging), but it also makes it clear when there's been an error instead of blurring that line. And the standard use that works for most people is easy to find and to use. What do you think of this approach? |
That seems simpler to me. Sounds good! |
@xtian this has been published in Graphqelm Elm package version 11.0.0 (more details in the changelog). Let me know how this works for you. Thanks for reporting the issue! |
Hey @xtian I think this is resolved so I'll close this out, but please let me know if you have any issues or feedback. Thanks! |
@dillonkearns Just got around to upgrading our app to 11.1.0. These changes work great. Thanks so much! |
Fantastic, glad to hear it! |
Graphqelm.Http
decodes data and error responses usingJson.Decode.oneOf
with thedata
field handled first. This swallows errors in a response like this wheresomeField
is nullable:Maybe an interface like this would work?
The other use-case to consider here is an operation with multiple queries or mutations where some succeed and some produce errors.
The text was updated successfully, but these errors were encountered: