Skip to content

Commit 058e1f6

Browse files
authored
Some Fixes (#75)
1 parent d67da8d commit 058e1f6

8 files changed

+69
-19
lines changed

docs/1-creating-a-graphql-server-project.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
1+
- [Create a new GraphQL server project](#create-a-new-graphql-server-project)
2+
- [Register the DB Context Service](#register-the-db-context-service)
3+
- [Configuring EF Migrations](#configuring-ef-migrations)
4+
- [Option 1 - Visual Studio: Package Manager Console](#option-1---visual-studio-package-manager-console)
5+
- [Option 2 - Command line](#option-2---command-line)
6+
- [Adding GraphQL](#adding-graphql)
7+
- [Adding Mutations](#adding-mutations)
8+
- [Summary](#summary)
29
# Create a new GraphQL server project
310

411
1. Create a new project for our GraphQL Server.
@@ -202,11 +209,13 @@ Commands Explained
202209

203210
![Start GraphQL server](images/1-start-server.png)
204211

205-
1. Start Banana Cake Pop and connect to our server.
212+
1. Start [Banana Cake Pop](https://chillicream.com/docs/bananacakepop) or use it built-in your browser at [http://localhost:5000/graphql/](http://localhost:5000/graphql/) and connect to our server (usually at [http://localhost:5000/graphql](http://localhost:5000/graphql)).
213+
**Note**: `<address>/graphql/` might **not** show mutations, make sure you use `<address>/graphql` (without trailing slash).
206214

207215
![Connect to GraphQL server with Banana Cake Pop](images/2-bcp-connect-to-server.png)
208216

209-
1. Click in the schema explorer and click on the `speakers` field in order to check the return type of the `speakers` field.
217+
1. Click in the schema explorer and click on the `speakers` field in order to check the return type of the `speakers` field.
218+
**Note**: You might have to reload the schema, you can do so by clicking the refresh-button in the upper-right corner.
210219

211220
![Explore GraphQL schema with Banana Cake Pop](images/3-bcp-schema-explorer.png)
212221

@@ -216,7 +225,7 @@ So, far we have added the Query root type to our schema, which allows us to quer
216225

217226
> For mutations we are using the [relay mutation pattern](https://relay.dev/docs/en/graphql-server-specification.html#mutations) which is commonly used in GraphQL.
218227

219-
A mutation consists of three components, the input, the payload and the mutation itself. In our case we want to create a mutation called `addSpeaker`, by convention, mutations are named as verbs, their inputs are the name with "Input" appended at the end, and they return an object that is the name with "Payload" appended.
228+
A mutation consists of three components, the **input**, the **payload** and the **mutation** itself. In our case we want to create a mutation called `addSpeaker`, by convention, mutations are named as verbs, their inputs are the name with "Input" appended at the end, and they return an object that is the name with "Payload" appended.
220229

221230
So, for our `addSpeaker` mutation, we create two types: `AddSpeakerInput` and `AddSpeakerPayload`.
222231

docs/2-controlling-nullability.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
- [Controlling nullability](#controlling-nullability)
2+
- [Configure Nullability](#configure-nullability)
3+
- [Summary](#summary)
14

25
# Controlling nullability
36

docs/3-understanding-dataLoader.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
- [Understanding GraphQL query execution and DataLoader](#understanding-graphql-query-execution-and-dataloader)
2+
- [Configure field scoped services](#configure-field-scoped-services)
3+
- [Adding the remaining data models](#adding-the-remaining-data-models)
4+
- [Adding DataLoader](#adding-dataloader)
5+
- [Fluent type configurations](#fluent-type-configurations)
6+
- [Summary](#summary)
17

28
# Understanding GraphQL query execution and DataLoader
39

@@ -188,7 +194,7 @@ The GraphQL execution engine will always try to execute fields in parallel in or
188194

189195
## Adding the remaining data models
190196

191-
In order to expand our GraphQL server model further we've got several more data models to add, and unfortunately it's a little mechanical. You can copy the following classes manually, or open the session 3 solution which is shown at the end.
197+
In order to expand our GraphQL server model further we've got several more data models to add, and unfortunately it's a little mechanical. You can copy the following classes manually, or open the [session 3 solution](/code/session-3).
192198

193199
1. Create an `Attendee.cs` class in the `Data` directory with the following code:
194200

@@ -431,7 +437,7 @@ After having everything in let us have a look at our schema and see if something
431437

432438
1. Open Banana Cake Pop and refresh the schema.
433439

434-
1. Head over to the schema explorer and have a look at the speaker.
440+
2. Head over to the schema explorer and have a look at the speaker. **Note**: You might have to reload the schema, you can do so by clicking the refresh-button in the upper-right corner.
435441

436442
![Connect to GraphQL server with Banana Cake Pop](images/10-bcp-schema-updated.png)
437443

docs/4-schema-design.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
- [GraphQL schema design approaches](#graphql-schema-design-approaches)
2+
- [Reorganize mutation types](#reorganize-mutation-types)
3+
- [Enable Relay support](#enable-relay-support)
4+
- [Build out the schema](#build-out-the-schema)
5+
- [Think beyond CRUD](#think-beyond-crud)
6+
- [Offer plural versions fields and be precise about field names](#offer-plural-versions-fields-and-be-precise-about-field-names)
7+
- [Summary](#summary)
8+
19
# GraphQL schema design approaches
210

311
In GraphQL, most APIs are designed in Relay style. Relay is Facebook's GraphQL client for React and represents Facebook's opinionated view on GraphQL. The GraphQL community adopted the Relay server specifications since it provides a battle-tested way of exposing GraphQL at massive scale.
@@ -45,14 +53,14 @@ First, we will restructure our GraphQL server so that it will better scale once
4553
public class UserError
4654
{
4755
public UserError(string message, string code)
48-
{
56+
{
4957
Message = message;
5058
Code = code;
51-
}
59+
}
5260

53-
public string Message { get; }
61+
public string Message { get; }
5462

55-
public string Code { get; }
63+
public string Code { get; }
5664
}
5765
}
5866
```
@@ -251,18 +259,19 @@ Now that we have reorganized our mutations, we will refactor the schema to a pro
251259

252260
> The following piece of code marked our `SpeakerType` as implementing the `Node` interface. It also defined that the `id` field that the node interface specifies is implemented by the `Id` on our entity. The internal `Id` is consequently rewritten to a global object identifier that contains the internal id plus the type name. Last but not least we defined a `ResolveNode` that is able to load the entity by `id`.
253261

254-
> ```csharp
255-
> descriptor
256-
> .ImplementsNode()
257-
> .IdField(t => t.Id)
258-
> .ResolveNode((ctx, id) => ctx.DataLoader<SpeakerByIdDataLoader>().LoadAsync(id, ctx.RequestAborted));
259-
> ```
262+
> ```csharp
263+
> descriptor
264+
> .ImplementsNode()
265+
> .IdField(t => t.Id)
266+
> .ResolveNode((ctx, id) => ctx.DataLoader<SpeakerByIdDataLoader>()
267+
> .LoadAsync(id, ctx.RequestAborted));
268+
> ```
260269

261270
1. Head over to the `Query.cs` and annotate the `id` argument of `GetSpeaker` with the `ID` attribute.
262271

263272
```csharp
264273
public Task<Speaker> GetSpeakerAsync(
265-
[ID(nameof(Speaker))]int id,
274+
[ID(nameof(Speaker))] int id,
266275
SpeakerByIdDataLoader dataLoader,
267276
CancellationToken cancellationToken) =>
268277
dataLoader.LoadAsync(id, cancellationToken);
@@ -380,7 +389,7 @@ We will start by adding the rest of the DataLoader that we will need. Then we wi
380389

381390
1. Now, add the missing type classes, `AttendeeType`, `TrackType`, and `SessionType` to the `Types` directory.
382391

383-
`AttendeeType`
392+
`AttendeeType.cs`
384393

385394
```csharp
386395
using System.Collections.Generic;
@@ -641,7 +650,7 @@ We will start by adding the rest of the DataLoader that we will need. Then we wi
641650
.AddType<SessionType>()
642651
.AddType<SpeakerType>()
643652
.AddType<TrackType>()
644-
.EnableRelaySupport());
653+
.EnableRelaySupport();
645654
```
646655

647656
Great, we now have our base schema and are ready to dive into some schema design topics. Although GraphQL has a single root query type, a single root mutation type, and a single root subscription type, Hot Chocolate allows splitting the root types into multiple classes, which will enable us to organize our schema around topics rather than divide it along its root types.

docs/5-understanding-middleware.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
- [Understanding middleware](#understanding-middleware)
2+
- [Add UseUpper middleware](#add-useupper-middleware)
3+
- [Create middleware attribute](#create-middleware-attribute)
4+
- [Middleware order](#middleware-order)
5+
- [Summary](#summary)
6+
17
# Understanding middleware
28

39
The field middleware is one of the foundational components in Hot Chocolate. Many features that you use like, for instance, the `ID` transformation from internal IDs to global object identifiers, are a field middleware. Even resolvers are compiled into a field middleware.

docs/6-adding-complex-filter-capabilities.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
- [Adding complex filter capabilities](#adding-complex-filter-capabilities)
2+
- [Add paging to your lists](#add-paging-to-your-lists)
3+
- [Add filter capabilities to the top-level field `sessions`](#add-filter-capabilities-to-the-top-level-field-sessions)
4+
- [Summary](#summary)
5+
16
# Adding complex filter capabilities
27

38
So far, our GraphQL server only exposes plain lists that would, at some point, grow so large that our server would time out. Moreover, we miss some filter capabilities for our session list so that the application using our backend can filter for tracks, titles, or search the abstract for topics.

docs/7-subscriptions.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
- [Adding real-time functionality with subscriptions](#adding-real-time-functionality-with-subscriptions)
2+
- [Refactor GraphQL API](#refactor-graphql-api)
3+
- [Add `registerAttendee` Mutation](#add-registerattendee-mutation)
4+
- [Add `checkInAttendee` Mutation](#add-checkinattendee-mutation)
5+
- [Add `onSessionScheduled` Subscription](#add-onsessionscheduled-subscription)
6+
- [Add `onAttendeeCheckedIn` subscription](#add-onattendeecheckedin-subscription)
7+
- [Summary](#summary)
8+
19
# Adding real-time functionality with subscriptions
210

311
For the last few parts of our journey through GraphQL, we have dealt with queries and mutations. In many APIs, this is all people need or want, but GraphQL also offers us real-time capabilities where we can formulate what data we want to receive when a specific event happens.

docs/8-testing-the-graphql-server.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
- [Testing the GraphQL server](#testing-the-graphql-server)
2+
- [Add a schema change test](#add-a-schema-change-test)
3+
- [Add a simple query tests](#add-a-simple-query-tests)
4+
15
# Testing the GraphQL server
26

37
There are many ways to test; what we want to have a look at is how we can test parts of the GraphQL schema without writing system tests.

0 commit comments

Comments
 (0)