Describing Errors in GraphQL
As developers, we know that errors are an inevitable part of building any application. Luckily, GraphQL provides us with powerful tools to handle them gracefully. By defining errors using GraphQL types and following established conventions, we can enhance the reliability and schema consumer experience of our GraphQL APIs.
In this chapter, we will explore the essential concepts and best practices for effectively describing errors in GraphQL. We will start by understanding how we throw errors, before learning how to specify errors with enums, and fully describe them with union-based responses. By the end of the chapter, we will learn why we need to mask all errors eventually and whitelist only those wanted by the developer on production.
In this chapter, we will cover the following topics:
- Understanding how we throw errors in GraphQL-based servers
- Using enums for error codes
- Treating errors as data
- Treating responses as unions ...