Understanding error masking
Error masking is a GraphQL technique that allows you to control the level of detail exposed in error messages sent to clients. It helps to prevent sensitive information from being leaked in error responses and promotes better security and privacy practices.
Let’s explore how error masking works with an example. First, start by bootstrapping an axolotl
project inside your command line:
npx @aexol/axolotl create-yoga
Then replace the ./schema.graphql
file with the following content:
type Query{ error: String! errorMasked: String! } schema{ query: Query }
Here, we have two resolvers to show you a normal error and a masked error. Ideally, your server framework should handle error masking under the hood, but I will show you how to create your own masked error mechanism.
Go to src/index.ts
and change the file’s content to turn off default error masking in GraphQL Yoga by setting the maskedErrors...