damikun / hotchocolate-mutation-errors

GraphQL mutation union erros (6a) with Hotchocolate GraphQL Server

Home Page:https://dev.to/damikun/graphql-mutation-union-erros-6a-with-hotchocolate-graphql-server-1b70

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About

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:

Hotchocolate 6a example comparing union vs shared interface query aproach

Content

Opensource workshop

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.

Quick start

  1. 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]
  1. Clone the repo
 git clone https://github.com/damikun/hotchocolate-mutation-errors.git
  1. cd to Src/API/ and run dotnet restore

  2. cd to Src/API/ClientApp and run yarn install or npm install

  3. from cmd run npx 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.

  1. After succesfull restoring cd to Src/API/ and run dotnet run.

  2. 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)

About

GraphQL mutation union erros (6a) with Hotchocolate GraphQL Server

https://dev.to/damikun/graphql-mutation-union-erros-6a-with-hotchocolate-graphql-server-1b70

License:MIT License


Languages

Language:TypeScript 56.7%Language:C# 38.3%Language:JavaScript 3.9%Language:CSS 0.7%Language:HTML 0.5%