Comments (9)
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:
- Ignore the error and act exactly like a regular successful response (this is the current Graphqelm behavior)
- Ignore the data and act exactly like a server error (perhaps this is a sensible default? It's hard to say, I'm not used to thinking about having both errors and a result in this kind of context so it's hard to know what the semantics should be)
- Give you both the data and the errors
For example, the Graphqelm.Http
module could provide the following send
functions (and similar for toTask
:
-- 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?
from elm-graphql.
What do you think of the multiple functions approach?
I think that's a great idea! Would definitely work for our use-case
from elm-graphql.
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.
from elm-graphql.
@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,
- If there are any
errors
in the response, the whole thing is treated as an error - When there are
errors
in the response, the contents ofdata
is always available as part of the data type (see the data type here) - If the decoder for
data
succeeds, the Error will containParsedData decodesTo
. Otherwise it will containUnparsedData Json.Decode.Value
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?
from elm-graphql.
That seems simpler to me. Sounds good!
from elm-graphql.
@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!
from elm-graphql.
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!
from elm-graphql.
@dillonkearns Just got around to upgrading our app to 11.1.0. These changes work great. Thanks so much!
from elm-graphql.
Fantastic, glad to hear it!
from elm-graphql.
Related Issues (20)
- Enhancement - Add support for Dgraph HOT 1
- non null list of non null list ofโฆ HOT 6
- Include an exhaustive query for each type HOT 3
- elm-graphql generation fails if there are no columns selected (Hasura) HOT 6
- Add operationName to mutation request body HOT 1
- Enum with underscore as a leading character, changed after generating elm code. HOT 1
- Scalar decoder fails when the field contains an object. HOT 1
- Scalars should not be encoded as json in mutations HOT 3
- Enforce nonempty list in required list arguments HOT 3
- Selecting implementation attributes from interfaces HOT 2
- Corrupt package data for 5.0.5? HOT 1
- Requesting feedback on the following changes to the serializeChildren function regarding field hashing HOT 2
- Can not find ScalarCodecs HOT 1
- Feature request: Convenience functions for primitive comparisons HOT 3
- Idea: serialize invalid JSON Input Values as arguments
- Missing fragment in Interface `Fragments` type HOT 1
- Idea: include deprecation warnings into the generated code as comments HOT 1
- Building large queries takes a long time and pauses the UI HOT 2
- Encode function for enums is missing HOT 1
- Generate input object helpers HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elm-graphql.