-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
[client] response errors sometimes not made available #577
Comments
hi @AlistairB, thank you i would be happy if you open a PR.
i think official interface should stay same. However, decode must check errors and fail if there are any (like you suggested). fetch :: (Monad m, FromJSON a) => (ByteString -> m ByteString) -> Args a -> m (Either String a)
For this case we could add an additional operation |
Please ignore for now David I know you are busy! I just spent some time trying to integrate my PR into my project and had some more thoughts which I wanted to record. There are 3 cases with the github graphql API
{
"data": {
"repository": null
},
"errors": [
{
"type": "NOT_FOUND",
"path": [
"repository"
],
"locations": [
{
"line": 7,
"column": 3
}
],
"message": "Could not resolve to a Repository with the name 'facebook/reacttt'."
}
]
}
{
"errors": [
{
"path": [
"query",
"repository",
"namee"
],
"extensions": {
"code": "undefinedField",
"typeName": "Repository",
"fieldName": "namee"
},
"locations": [
{
"line": 8,
"column": 4
}
],
"message": "Field 'namee' doesn't exist on type 'Repository'"
}
]
} I assume exception is similar but not sure how to reproduce. Actually, looking at https://graphql.org/learn/serving-over-http/#response it seems that in the exception case you may get the data field, so it could be more case 2. I think in some ways the current functionality is nice for the not found case. The issue is there may be other errors as well when you get a I would suggest the following for fetch :: (Monad m, FromJSON a) => (ByteString -> m ByteString) -> Args a -> m (Either FetchError ([GQLError], a))
data FetchError =
ResultParseFailure String
| NoResultWithErrors (NonEmpty GQLError) As such in the 3 above cases you get (vaguely sketched):
Then you also have the parse failure result which will also be a In the first 1 my code will sanity check there are no errors and happily use the In the second case:
In the third / left cases:
I guess as part of this you would need to add |
HI @AlistairB. i think that
what do you think? |
@nalchevanidze Yeah I think it is ok. It's fairly unclear to me the right modelling, partly because I am not that familiar with graphql. For example, the 404/Not Found result is usually not considered exceptional with restful apis, so it makes me think it should be a Anyway, I think your modelling is fine, but I would tweak it slightly.
There is also another case of parse failure, which I modelled with a sum type. morpheus-graphql/morpheus-graphql-client/src/Data/Morpheus/Client/Internal/Types.hs Lines 49 to 59 in b760851
is how I did it, which is slightly different in that you get a |
@nalchevanidze so are you happy with the following? fetch :: (Monad m, FromJSON a) => (ByteString -> m ByteString) -> Args a -> m (Either (FetchError a) a)
data FetchError a
= FetchParseFailure String
| FetchProducedErrors (NonEmpty GQLError) (Maybe a) |
@AlistairB yes. let try it |
Hi,
When using the
updateCheckRun
mutation on github graphql api in one case I get the following response.The relevant graphql for this is:
As per this definition
"updateCheckRun": null
is a perfectly valid response and will json decode correctly. As such, morpheus assumes that everything is fine, however there are in fact errors. I believe the reasonUpdateCheckRunPayload
is nullable is because in the error case it won't be returned.So I guess the assumption that a successful decode of the response = no errors is incorrect. ie. https://github.com/morpheusgraphql/morpheus-graphql/blob/master/morpheus-graphql-client/src/Data/Morpheus/Client/Fetch.hs#L63 perhaps this success case should also pattern match on an empty error list.
Or you might want 3 responses of, success, success with errors, parse failure.
I'd happy to attempt a PR if you know what the ideal solution is.
The text was updated successfully, but these errors were encountered: