Java GraphQL error handling with batching - Stack Overflow

I am using quarkus with SmallRye GraphQLGiven this resolver:public Person partner(@Source Person pers

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

Unfortunately 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

相关推荐

  • Java GraphQL error handling with batching - Stack Overflow

    I am using quarkus with SmallRye GraphQLGiven this resolver:public Person partner(@Source Person pers

    13天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信