Hi, I have a question regarding Spring graphQL data/error management.
I have a use case where I want to return several results, including the error ones, as a Union.
something like this:
extend type Mutation {
userCreate(): UserCreatePayload
}
union UserCreatePayload = UserCreated | UserAlreadyExists
I have a MutationsResolver that handles the
userCreate
mutation by calling a
UserService
that is transactional.
When trying to create a user, if the user already exists, I'm throwing a
UserAlreadyExist
Exception that is handled in the mutation resolver with a try/catch block and then mapped to the UserAlreadyExists type in graphql.
The problem is that as the UserService is transactional, whenever I throw the exception, the transaction is marked a rollbackOnly by spring (which is good) and then the graphql flow goes through the
DefaultGraphQLErrorHandler that finally return an error to the end user.
I would like to have the exactly same behavior except for the graphql error handler returning a GraphqlError. Instead I want to return the
UserAlreadyExists
type I defined in the graphql schema.
Is there anyway to do so? (I do not want to use sealed classes instead of exceptions in the service as the code gets dirty)
Thanks!