# Getting started with GraphQL in .NET Core - Hot Chocolate

> In this tutorial, you will walk through the basics of creating a GraphQL server with Hot Chocolate.

Canonical source: https://chillicream.com/docs/hotchocolate/get-started-with-graphql-in-net-core

By the end of this guide, you will have a running GraphQL server that responds to queries. You will use the Hot Chocolate project template, explore the generated code, and execute your first query in the Nitro GraphQL IDE.

**Prerequisites:** [.NET 8 SDK](https://dotnet.microsoft.com/download) or later.

## Create the Project

Install the Hot Chocolate templates.

Bash

```
dotnet new install HotChocolate.Templates
```

Create a new project from the template.

Bash

```
dotnet new graphql --name GettingStarted
```

This creates a `GettingStarted` directory with the project files. Open it in your editor.

## Explore the Generated Code

### Domain Types

The `Types` directory contains two record types that represent the domain model.

C#

```
public record Author(string Name);
```

C#

```
public record Book(string Title, Author Author);
```

These are regular C# types. Hot Chocolate infers the GraphQL schema from them.

### Query Type

The `Query` class defines the root type for read operations. Each public method becomes a field that clients can query.

C#

```
[QueryType]
public static partial class Query
{
    public static Book GetBook()
        => new Book("C# in depth.", new Author("Jon Skeet"));
}
```

The `[QueryType]` attribute tells the source generator to register this class as part of the GraphQL Query type. The class must be `partial` so the source generator can add the registration code at build time.

The method `GetBook` becomes a field named `book` in the schema. Hot Chocolate strips the `Get` prefix by convention.

### Program.cs

The generated `Program.cs` sets up the server.

C#

```
builder.AddGraphQL()
```

`AddGraphQL` returns an `IRequestExecutorBuilder` for configuring the GraphQL server. The template also calls a source-generated `AddTypes` method that registers all types decorated with attributes like `[QueryType]` in the current assembly.

C#

```
app.MapGraphQL()
```

`MapGraphQL` exposes the GraphQL endpoint at `/graphql`. This is where clients send queries and where Nitro (the built-in GraphQL IDE) is served.

C#

```
app.RunWithGraphQLCommands(args)
```

`RunWithGraphQLCommands` works like `Run()` but adds developer commands. For example, you can export the schema as SDL.

Bash

```
dotnet run -- schema export
```

This writes a `schema.graphqls` file to your project directory.

## Run the Server

Bash

```
dotnet run
```

If everything worked, the terminal output includes a line like this:

```
Now listening on: http://localhost:5095
```

Open <http://localhost:5095/graphql> in your browser. You should see the Nitro GraphQL IDE.

![GraphQL IDE](https://chillicream.com/images/hotchocolate-docs/getting-started-nitro.webp)

Click **Create Document**, verify the HTTP Endpoint matches your server URL, and click **Apply**.

![GraphQL IDE: Setup](https://chillicream.com/images/hotchocolate-docs/getting-started-nitro-setup.webp)

You should see the editor with **Schema available** at the bottom right.

![GraphQL IDE: Editor](https://chillicream.com/images/hotchocolate-docs/getting-started-nitro-editor.webp)

## Execute a Query

Paste the following query into the **Request** pane.

GraphQL

```
{
  book {
    title
    author {
      name
    }
  }
}
```

Click **Run**. The **Response** pane should show:

JSON

```
{
  "data": {
    "book": {
      "title": "C# in depth.",
      "author": {
        "name": "Jon Skeet"
      }
    }
  }
}
```

![GraphQL IDE: Executing a query](https://chillicream.com/images/hotchocolate-docs/getting-started-nitro-query.webp)

You can browse the schema by clicking the **Schema** tab next to **Operation**. The **Schema Definition** tab shows the raw SDL.

![GraphQL IDE: Schema](https://chillicream.com/images/hotchocolate-docs/getting-started-nitro-schema.webp)

Your GraphQL server is running and responding to queries.

## Next Steps

- **"I want to learn about the type system."** See [Defining a Schema](https://chillicream.com/docs/hotchocolate/defining-a-schema) for queries, mutations, subscriptions, and all the GraphQL types.
- **"I want to fetch data from a database."** See [DataLoader](https://chillicream.com/docs/hotchocolate/fetching-data/batching/dataloader) for batched data fetching, or [Entity Framework](https://chillicream.com/docs/hotchocolate/fetching-data/integrations/entity-framework) for EF Core integration.
- **"I want a deeper tutorial."** Check out the [GraphQL Workshop](https://github.com/ChilliCream/graphql-workshop) for a hands-on walkthrough covering types, resolvers, DataLoaders, filtering, and more.
- **"I'm new to GraphQL."** Read the [official GraphQL introduction](https://graphql.org/learn/) to understand the concepts before diving deeper into Hot Chocolate.
[Edit this page on GitHub](https://github.com/ChilliCream/graphql-platform/edit/main/website/content/docs/hotchocolate/get-started-with-graphql-in-net-core.md)

Last updated on **June 30, 2026** by **Tobias Tengler**
