smallrye / smallrye-graphql

Implementation for MicroProfile GraphQL
Apache License 2.0
160 stars 91 forks source link

Business Error Reporting #1423

Open t1 opened 2 years ago

t1 commented 2 years ago

Discussed in https://github.com/smallrye/smallrye-graphql/discussions/1410

Add a way to configure return types to be wrapped in Result types and map the exceptions accordingly.

@Query
@GraphQLResult
public Order order(@Id String id) throws OrderNotFoundException, OrderLockedException { ... }

Results in a schema:

type OrderResult {
  order: Order
  error_orderLocked: OrderLocked
  error_orderNotFound: OrderNotFound
}

type Query {
  order(id: ID): OrderResult
}
t1 commented 2 years ago

In a later step, the @GraphQLResult annotation could take an enum parameter to define the type of wrapping applied. The above default is ERROR_FIELDS, a second value is UNION resulting in this schema:

union OrderResult = Order | OrderLocked | OrderNotFound

type OrderLocked {
  ...
}

type OrderNotFound {
  ...
}