Dealing with errors in Graphql is a topic on which there are numerous articles and recommendations, but there are not many real-world examples of how to implement a concrete approach under a given language and GraphQL server.
Full Docs: GraphQL Mutation Error hadnling
This repo is related to article: GraphQL mutation union erros (6a) with Hotchocolate GraphQL Server or Opensource FullStack App Example.
It provides implementation of stage 6a mutation error handling from Marc-Andre Giroux Guide to graphql errors under Hotchocolate (.Net) GraphQL Server including some base integration with MediatR.
These are the advantages of the 6a approach:
- ✅Pro: Expressive and Discoverable Schema
- ✅Pro: Support for Multiple Errors
- ✅Pro: Easier Evolution
Before we begin, let me show you an example from the playground of 6a error. The pattern allows you to choose whether to use one concrete type as the union
or group them all together using the common IBaseError
interface:
https://github.com/damikun/trouble-training
This open source fullstack WorkShop shows an example WebHook application with a self-hosted IdentityServer and guides you on how to set up distributed tracing and monitoring for your app.
- Make sure you have Net 5.0 SDK installed. You can cheque the SDK version by running: dotnet --list-sdks in your terminal.
#Example output on Windows
PS C:\Users\dakupc> dotnet --list-sdks
5.0.100 [C:\Program Files\dotnet\sdk]
5.0.201 [C:\Program Files\dotnet\sdk]
- Clone the repo
git clone https://github.com/damikun/hotchocolate-mutation-errors.git
-
cd
toSrc/API/
and rundotnet restore
-
cd
toSrc/API/ClientApp
and runyarn install
ornpm install
-
from
cmd
runnpx tailwindcss-cli@latest init
(in case you dont have tailwind cli installed)
NOTE: This may take some time since all
node_modules
of Frontend SPA needs to be installed on first startup.
-
After succesfull restoring
cd
toSrc/API/
and rundotnet run
. -
Demo runs on:
https://localhost:5001
In case you have error with certificates. Install Dev. Certificates:
dotnet dev-certs https --trust
In case you have problem to restor frontend packages (or compiler errors) delete yarn.lock
file and re-run yarn install
(similar for npm)