Expose expected errors within Grafbase Edge Resolvers

Jakub WieczorekJakub WieczorekJamie BartonJamie Barton
Expose expected errors within Grafbase Edge Resolvers

Grafbase now supports throwing expected errors from inside resolvers!

As of this update, all errors occurring within resolvers are automatically masked to prevent exposure of internal processes to the client. However, for cases where revealing expected errors is necessary, we've introduced a new feature.

Users can now utilize the GraphQLError from the graphql package to intentionally throw and expose these errors.

import { GraphQLError } from 'graphql' function Resolver(_, { args }) { const { number } = args if (number >= 10) { throw new GraphQLError( `You must provide a number less than 10. You passed ${number}!`, ) } // ... }

Make sure you're using grafbase@0.28.0 or later.

When GraphQLError is thrown you will get a response similar to the below:

{ "errors": [ { "message": "You must provide a number less than 10. You passed 20", "locations": [ { "line": 2, "column": 3 } ], "path": ["..."] } ], "data": null }

We'd love to hear your feedback and ideas, so join us on Discord.