First Server
In this lesson, we will create our first GraphQL server using Hot Chocolate.
First, let's go to the lesson directory.
cd src/Chapter1/Lesson2/Begin
This directory is actually completely empty since we will start from scratch.
Next, we will install the Hot Chocolate templates for .NET.
dotnet new -i HotChocolate.Templates::14.0.0-p.106
You should now see the Hot Chocolate templates listed in the console output.
Now that we have the Hot Chocolate templates installed, we can create a new project using the Hot Chocolate GraphQL template.
dotnet new graphql
This will create a new project with the following structure:
.
├── Begin.csproj
├── Program.cs
└── Types
├── Author.cs
├── Book.cs
└── Query.cs
Start the server by running the following command:
dotnet run
By default, the GraphQL server will listen on port 5000. According to the GraphQL over HTTP spec, a GraphQL server will by default listen on the /graphql
endpoint. Open your web browser and enter the following address: http://localhost:5095/graphql/
Tasks
- Explore the schema in the Schema Reference tab.
- Query the
book
field on theQuery
type. - Add an address object and expose it on the
Author
type. - Query the address of the author.