-
-
Notifications
You must be signed in to change notification settings - Fork 439
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
How to handle a partial error? #407
Comments
With #395 it's possible to break only the response for the current field: query {
posts {
id
title
}
users {
id
name
}
} Given the request for users is not allowed or fails for any reason, result will be: {
// data of posts
"data": {"posts": [ ... ]},
// error for "users"
"errors": [
{ ... }
]
} Not what exactly what you where asking for, but still an improvement over the current behavior in stable releases (Right now the whole request is interrupted). Not sure how to handle partial errors within a field though. union UserRespone = User | Error query {
users {
... on Error { message }
... on User { id name }
}
} Not sure if this is a good idea. I do filter the models e.g using a (global) scope to only get the ones permitted in the first place. |
Multiple options here, really dependent on what you want to achieve and what scenario you are dealing with.
All of those are already possible in Lighthouse. Does this satisfy your question? |
@JBBr
This is what I want to achieve! |
The best way would be @can. Something like @method should work fine as well. type Post {
allowed: String
restricted: String @method(name: "getRestrictedIfAdmin")
} On the object that is returned by your public function getRestrictedIfAdmin(array $args, Context $context)
{
if(!$context->user()->isAdmin()){
throw new AuthenticationException('This content is highly confidential.');
}
return $this->superSecretAttribute;
} With #395 you will be able to use middleware here as well. So yeah, plenty of options. |
Execuse me. I have multiple queries the posts query authorized via laravel policies and graphql @can directive and fails (policy return false). { errors: [ If I understand correctly, I need to use ErrorPool, but where can I place it to collect errors? Thank you. |
I thought there is a standard way to do this in the upstream lib
webonyx/graphql-php
.But looks like there isn't? Does this means we should do the error handling things in Lighthouse…?
Copied from webonyx/graphql-php#374 (comment)
Suppose we are querying a list of post:
The requesting user does not have the read permission of some of the retrieved posts.
Say if we got 10 posts, 2 of them are not allowed to be read by the requesting user (or maybe only the
title
field is can be read).How can I handle such a "partial error" case?
Describe the solution you'd like
A response with
errors
field like:If you just
new Error
you are breaking the whole response.How can I collect the error with out breaking the whole response with both
data
anderrors
in the json response?I saw this piece of code here
https://github.com/nuwave/lighthouse/blob/master/src/GraphQL.php#L119-L145
does it mean I can inject error into the
errors
field while still output thedata
field?The text was updated successfully, but these errors were encountered: