Building a GraphQL API with HotChocolate - Part 1

Commencing today, we initiate a series of articles that delve into the creation of a GraphQL API using C#. Throughout this exploration, we aim to elucidate the concept of GraphQL, addressing the challenges it seeks to overcome. Subsequently, we will demonstrate the process of implementing an API utilizing the HotChocolate library.

Creating an API might initially appear straightforward: one needs to establish endpoints with suitable verbs, enabling clients to retrieve or submit data. However, complications arise when new attributes are required, or when clients don't require all the returned data. This often leads to the creation of custom endpoints for highly specific requests, resulting in the need to manage extensive code maintenance.

To circumvent the challenges of this maintenance nightmare, a novel technology pioneered by Facebook in the early 2010s, named GraphQL, was introduced. GraphQL offers a comprehensive and intelligible representation of the data within our API, empowering clients to request precisely the information they require and nothing beyond that.

Throughout this series, we will delve into the precise nature of GraphQL and elucidate the reasons for its widespread adoption. The concept will be demonstrated through practical examples, specifically written in C# using the corresponding library, HotChocolate.

The subsequent textbooks prove useful for concluding this series.

Learning GraphQL: Declarative Data Fetching for Modern Web Apps (Porcello, Banks)

Apps and Services with .NET 8: Build practical projects with Blazor, .NET MAUI, gRPC, GraphQL, and other enterprise technologies (Price)

Without further ado and as usual, let's begin with a few prerequisites to correctly understand the underlying concepts. Continue here.