Managing GQL errors
The GraphQL specification defines the error’s format. We have seen an example of it in the Implementing our first GQL query resolver section. The common properties are:
message
: A message descriptionlocations
: The GraphQL request document’s coordinates that triggered the errorpath
: The response field that encountered the errorextensions
: Optional field to include custom output properties
With Mercurius, we can customize the message
error by throwing or returning an Error
object:
const resolvers = { Query: { family: async function familyFunc (parent, args, context, info) { const familyData = await context.familyDL.load(args.id) if (!familyData) { ...