Skip to content

Commit e9da1fc

Browse files
committed
Added session 3
1 parent ee8a4f8 commit e9da1fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+948
-1399
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The GraphQL schema can be found [here](code/complete/schema.graphql).
3030
|------------------------------------------------------------|-------------------------------------------------------|
3131
| [Session #1](docs/1-creating-a-graphql-server-project.md) | Creating a new GraphQL server project. |
3232
| [Session #2](docs/2-controlling-nullability.md) | Controlling nullability. |
33-
| [Session #3](docs/3-understanding-dataLoader.md) | Understanding GraphQL query execution and DataLoader. |
33+
| [Session #3](docs/3-understanding-data-loader.md) | Understanding DataLoader. |
3434
| [Session #4](docs/4-schema-design.md) | GraphQL schema design approaches. |
3535
| [Session #5](docs/5-understanding-middleware.md) | Understanding middleware. |
3636
| [Session #6](docs/6-adding-complex-filter-capabilities.md) | Adding complex filter capabilities. |

code/session-3/.config/dotnet-tools.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"isRoot": true,
44
"tools": {
55
"dotnet-ef": {
6-
"version": "5.0.0",
6+
"version": "8.0.7",
77
"commands": [
88
"dotnet-ef"
9-
]
9+
],
10+
"rollForward": false
1011
}
1112
}
1213
}

code/session-3/.vscode/launch.json

Lines changed: 0 additions & 34 deletions
This file was deleted.

code/session-3/.vscode/tasks.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

code/session-3/ConferencePlanner.sln

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,22 @@
1-
2-
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26124.0
5-
MinimumVisualStudioVersion = 15.0.26124.0
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphQL", "GraphQL\GraphQL.csproj", "{48385280-56F1-4937-9655-E6A79184740B}"
7-
EndProject
8-
Global
9-
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10-
Debug|Any CPU = Debug|Any CPU
11-
Debug|x64 = Debug|x64
12-
Debug|x86 = Debug|x86
13-
Release|Any CPU = Release|Any CPU
14-
Release|x64 = Release|x64
15-
Release|x86 = Release|x86
16-
EndGlobalSection
17-
GlobalSection(SolutionProperties) = preSolution
18-
HideSolutionNode = FALSE
19-
EndGlobalSection
20-
GlobalSection(ProjectConfigurationPlatforms) = postSolution
21-
{48385280-56F1-4937-9655-E6A79184740B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22-
{48385280-56F1-4937-9655-E6A79184740B}.Debug|Any CPU.Build.0 = Debug|Any CPU
23-
{48385280-56F1-4937-9655-E6A79184740B}.Debug|x64.ActiveCfg = Debug|Any CPU
24-
{48385280-56F1-4937-9655-E6A79184740B}.Debug|x64.Build.0 = Debug|Any CPU
25-
{48385280-56F1-4937-9655-E6A79184740B}.Debug|x86.ActiveCfg = Debug|Any CPU
26-
{48385280-56F1-4937-9655-E6A79184740B}.Debug|x86.Build.0 = Debug|Any CPU
27-
{48385280-56F1-4937-9655-E6A79184740B}.Release|Any CPU.ActiveCfg = Release|Any CPU
28-
{48385280-56F1-4937-9655-E6A79184740B}.Release|Any CPU.Build.0 = Release|Any CPU
29-
{48385280-56F1-4937-9655-E6A79184740B}.Release|x64.ActiveCfg = Release|Any CPU
30-
{48385280-56F1-4937-9655-E6A79184740B}.Release|x64.Build.0 = Release|Any CPU
31-
{48385280-56F1-4937-9655-E6A79184740B}.Release|x86.ActiveCfg = Release|Any CPU
32-
{48385280-56F1-4937-9655-E6A79184740B}.Release|x86.Build.0 = Release|Any CPU
33-
EndGlobalSection
34-
EndGlobal
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphQL", "GraphQL\GraphQL.csproj", "{D96823B9-86D3-4D54-A803-F1D43AEBE1FD}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(SolutionProperties) = preSolution
14+
HideSolutionNode = FALSE
15+
EndGlobalSection
16+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
17+
{D96823B9-86D3-4D54-A803-F1D43AEBE1FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{D96823B9-86D3-4D54-A803-F1D43AEBE1FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{D96823B9-86D3-4D54-A803-F1D43AEBE1FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{D96823B9-86D3-4D54-A803-F1D43AEBE1FD}.Release|Any CPU.Build.0 = Release|Any CPU
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
namespace ConferencePlanner.GraphQL
2-
{
3-
public record AddSpeakerInput(
4-
string Name,
5-
string? Bio,
6-
string? WebSite);
7-
}
1+
namespace ConferencePlanner.GraphQL;
2+
3+
public sealed record AddSpeakerInput(
4+
string Name,
5+
string? Bio,
6+
string? Website);
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
using ConferencePlanner.GraphQL.Data;
22

3-
namespace ConferencePlanner.GraphQL
4-
{
5-
public class AddSpeakerPayload
6-
{
7-
public AddSpeakerPayload(Speaker speaker)
8-
{
9-
Speaker = speaker;
10-
}
3+
namespace ConferencePlanner.GraphQL;
114

12-
public Speaker Speaker { get; }
13-
}
14-
}
5+
public sealed class AddSpeakerPayload(Speaker speaker)
6+
{
7+
public Speaker Speaker { get; } = speaker;
8+
}
Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
1-
using Microsoft.EntityFrameworkCore;
2-
3-
namespace ConferencePlanner.GraphQL.Data
4-
{
5-
public class ApplicationDbContext : DbContext
6-
{
7-
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
8-
: base(options)
9-
{
10-
}
11-
12-
protected override void OnModelCreating(ModelBuilder modelBuilder)
13-
{
14-
modelBuilder
15-
.Entity<Attendee>()
16-
.HasIndex(a => a.UserName)
17-
.IsUnique();
18-
19-
// Many-to-many: Session <-> Attendee
20-
modelBuilder
21-
.Entity<SessionAttendee>()
22-
.HasKey(ca => new { ca.SessionId, ca.AttendeeId });
23-
24-
// Many-to-many: Speaker <-> Session
25-
modelBuilder
26-
.Entity<SessionSpeaker>()
27-
.HasKey(ss => new { ss.SessionId, ss.SpeakerId });
28-
}
29-
30-
public DbSet<Session> Sessions { get; set; } = default!;
31-
32-
public DbSet<Track> Tracks { get; set; } = default!;
33-
34-
public DbSet<Speaker> Speakers { get; set; } = default!;
35-
36-
public DbSet<Attendee> Attendees { get; set; } = default!;
37-
}
38-
}
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace ConferencePlanner.GraphQL.Data;
4+
5+
public sealed class ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
6+
: DbContext(options)
7+
{
8+
public DbSet<Attendee> Attendees { get; set; }
9+
10+
public DbSet<Session> Sessions { get; set; }
11+
12+
public DbSet<Speaker> Speakers { get; set; }
13+
14+
public DbSet<Track> Tracks { get; set; } = default!;
15+
16+
protected override void OnModelCreating(ModelBuilder modelBuilder)
17+
{
18+
modelBuilder
19+
.Entity<Attendee>()
20+
.HasIndex(a => a.Username)
21+
.IsUnique();
22+
23+
// Many-to-many: Session <-> Attendee
24+
modelBuilder
25+
.Entity<SessionAttendee>()
26+
.HasKey(sa => new { sa.SessionId, sa.AttendeeId });
27+
28+
// Many-to-many: Speaker <-> Session
29+
modelBuilder
30+
.Entity<SessionSpeaker>()
31+
.HasKey(ss => new { ss.SessionId, ss.SpeakerId });
32+
}
33+
}
Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
using System.Collections.Generic;
21
using System.ComponentModel.DataAnnotations;
32

4-
namespace ConferencePlanner.GraphQL.Data
3+
namespace ConferencePlanner.GraphQL.Data;
4+
5+
public sealed class Attendee
56
{
6-
public class Attendee
7-
{
8-
public int Id { get; set; }
7+
public int Id { get; set; }
98

10-
[Required]
11-
[StringLength(200)]
12-
public string? FirstName { get; set; }
9+
[StringLength(200)]
10+
public required string FirstName { get; set; }
1311

14-
[Required]
15-
[StringLength(200)]
16-
public string? LastName { get; set; }
12+
[StringLength(200)]
13+
public required string LastName { get; set; }
1714

18-
[Required]
19-
[StringLength(200)]
20-
public string? UserName { get; set; }
15+
[StringLength(200)]
16+
public required string Username { get; set; }
2117

22-
[StringLength(256)]
23-
public string? EmailAddress { get; set; }
18+
[StringLength(256)]
19+
public string? EmailAddress { get; set; }
2420

25-
public ICollection<SessionAttendee> SessionsAttendees { get; set; } =
26-
new List<SessionAttendee>();
27-
}
28-
}
21+
public ICollection<SessionAttendee> SessionsAttendees { get; set; } =
22+
new List<SessionAttendee>();
23+
}
Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
1-
using System;
2-
using System.Collections.Generic;
31
using System.ComponentModel.DataAnnotations;
42

5-
namespace ConferencePlanner.GraphQL.Data
3+
namespace ConferencePlanner.GraphQL.Data;
4+
5+
public sealed class Session
66
{
7-
public class Session
8-
{
9-
public int Id { get; set; }
7+
public int Id { get; set; }
108

11-
[Required]
12-
[StringLength(200)]
13-
public string? Title { get; set; }
9+
[StringLength(200)]
10+
public required string Title { get; set; }
1411

15-
[StringLength(4000)]
16-
public string? Abstract { get; set; }
12+
[StringLength(4000)]
13+
public string? Abstract { get; set; }
1714

18-
public DateTimeOffset? StartTime { get; set; }
15+
public DateTimeOffset? StartTime { get; set; }
1916

20-
public DateTimeOffset? EndTime { get; set; }
17+
public DateTimeOffset? EndTime { get; set; }
2118

22-
// Bonus points to those who can figure out why this is written this way
23-
public TimeSpan Duration =>
24-
EndTime?.Subtract(StartTime ?? EndTime ?? DateTimeOffset.MinValue) ??
25-
TimeSpan.Zero;
19+
// Bonus points to those who can figure out why this is written this way.
20+
public TimeSpan Duration =>
21+
EndTime?.Subtract(StartTime ?? EndTime ?? DateTimeOffset.MinValue) ??
22+
TimeSpan.Zero;
2623

27-
public int? TrackId { get; set; }
24+
public int? TrackId { get; set; }
2825

29-
public ICollection<SessionSpeaker> SessionSpeakers { get; set; } =
30-
new List<SessionSpeaker>();
26+
public ICollection<SessionSpeaker> SessionSpeakers { get; set; } =
27+
new List<SessionSpeaker>();
3128

32-
public ICollection<SessionAttendee> SessionAttendees { get; set; } =
33-
new List<SessionAttendee>();
29+
public ICollection<SessionAttendee> SessionAttendees { get; set; } =
30+
new List<SessionAttendee>();
3431

35-
public Track? Track { get; set; }
36-
}
37-
}
32+
public Track? Track { get; set; }
33+
}

0 commit comments

Comments
 (0)