I am using quarkus with SmallRye GraphQL
Given this resolver:
public Person partner(@Source Person person) throws GraphQLException {
Person partner = service.getPartner(person);
if (partner == null) {
throw new GraphQLException("No partner for person " + person.getName());
}
return partner;
}
I get responses like this:
{
"errors": [
{
"message": "No partner for person John Doe",
...
},
{
"message": "No partner for person James Doe",
...
}
],
"data": {
"allPersons": [
{
"name": "Test Doe",
"partner": {
"name": "Jane Doe"
}
},
{
"name": "John Doe",
"partner": null
},
{
"name": "James Doe",
"partner": null
}
]
}
}
How can I replicate this behavior using a batched resolver like this:
public List<Person> partner(@Source List<Person> persons) throws GraphQLException {
...
}
It seems to be a trivial problem, but I can't find any resources on the matter. Another post suggests that it is not possible to return both errors and data from a resolver (How to return both error and data in a graphql resolver?). Is there any workaround / alternative approach for this problem?
I am using quarkus with SmallRye GraphQL
Given this resolver:
public Person partner(@Source Person person) throws GraphQLException {
Person partner = service.getPartner(person);
if (partner == null) {
throw new GraphQLException("No partner for person " + person.getName());
}
return partner;
}
I get responses like this:
{
"errors": [
{
"message": "No partner for person John Doe",
...
},
{
"message": "No partner for person James Doe",
...
}
],
"data": {
"allPersons": [
{
"name": "Test Doe",
"partner": {
"name": "Jane Doe"
}
},
{
"name": "John Doe",
"partner": null
},
{
"name": "James Doe",
"partner": null
}
]
}
}
How can I replicate this behavior using a batched resolver like this:
public List<Person> partner(@Source List<Person> persons) throws GraphQLException {
...
}
It seems to be a trivial problem, but I can't find any resources on the matter. Another post suggests that it is not possible to return both errors and data from a resolver (How to return both error and data in a graphql resolver?). Is there any workaround / alternative approach for this problem?
Share Improve this question asked Mar 13 at 21:33 janbikojanbiko 915 bronze badges1 Answer
Reset to default 0Unfortunately no, I don't think that is possible with batching. It would be achievable if there was some API to append custom errors to the response, but I guess it would be quite clunky to do... You may report that as a feature request in the project repository if you want (I am the maintainer).
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744684324a4587822.html
评论列表(0条)