apollo – How can domain (user) errors in GraphQL mutations be handled in a unified way?

In our team, we are in the process of migrating from a REST API to GraphQL.

Our GraphQL mutations return two types of errors:

We use the repository pattern to abstract API calls.

With Apollo Client, top-level errors can be easily handled globally using interceptors.

However, userErrors still need to be handled individually in each repository, which can lead to code duplication or missed error handling.

Our goal is to find a way to handle domain errors in a unified manner.

One idea that has been suggested is to return domain errors as top-level GraphQL errors.

We understand that this is not considered a GraphQL best practice,

but we are wondering if it could be an acceptable compromise in a practical, internal setting.

Question:

From a GraphQL best-practice perspective, what is the recommended approach to unify the handling of domain (userErrors) errors, given that the API is abstracted via the repository pattern?

Additionally, is the approach of moving them to top-level errors ever used in practice as a reasonable compromise?

Are there established patterns or common solutions (such as using a common result wrapper, Apollo interceptors, etc.)?


Environment:

Android (Kotlin) + Apollo Client 3.x

Read more here: Source link