Skip to content

Commit c57be1f

Browse files
committed
Cleanup
1 parent 8c892f1 commit c57be1f

24 files changed

+72
-92
lines changed

code/complete/GraphQL/Attendees/AttendeeNode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
using System.Linq;
33
using System.Threading;
44
using System.Threading.Tasks;
5-
using Microsoft.EntityFrameworkCore;
65
using ConferencePlanner.GraphQL.Data;
76
using ConferencePlanner.GraphQL.DataLoader;
87
using HotChocolate;
98
using HotChocolate.Types;
109
using HotChocolate.Types.Relay;
10+
using Microsoft.EntityFrameworkCore;
1111

12-
namespace ConferencePlanner.GraphQL.Types
12+
namespace ConferencePlanner.GraphQL.Attendees
1313
{
1414
[Node]
1515
[ExtendObjectType]

code/complete/GraphQL/Attendees/AttendeeQueries.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public class AttendeeQueries
1919
[UseApplicationDbContext]
2020
[UsePaging]
2121
public IQueryable<Attendee> GetAttendees(
22-
[ScopedService] ApplicationDbContext context) =>
23-
context.Attendees;
22+
[ScopedService] ApplicationDbContext context)
23+
=> context.Attendees;
2424

2525
/// <summary>
2626
/// Gets an attendee by its identifier.
@@ -32,13 +32,13 @@ public IQueryable<Attendee> GetAttendees(
3232
public Task<Attendee> GetAttendeeByIdAsync(
3333
[ID(nameof(Attendee))] int id,
3434
AttendeeByIdDataLoader attendeeById,
35-
CancellationToken cancellationToken) =>
36-
attendeeById.LoadAsync(id, cancellationToken);
35+
CancellationToken cancellationToken)
36+
=> attendeeById.LoadAsync(id, cancellationToken);
3737

3838
public async Task<IEnumerable<Attendee>> GetAttendeesByIdAsync(
3939
[ID(nameof(Attendee))] int[] ids,
4040
AttendeeByIdDataLoader attendeeById,
41-
CancellationToken cancellationToken) =>
42-
await attendeeById.LoadAsync(ids, cancellationToken);
41+
CancellationToken cancellationToken)
42+
=> await attendeeById.LoadAsync(ids, cancellationToken);
4343
}
4444
}

code/complete/GraphQL/Attendees/AttendeeSubscriptions.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ public class AttendeeSubscriptions
1616
[Subscribe(With = nameof(SubscribeToOnAttendeeCheckedInAsync))]
1717
public SessionAttendeeCheckIn OnAttendeeCheckedIn(
1818
[ID(nameof(Session))] int sessionId,
19-
[EventMessage] int attendeeId,
20-
SessionByIdDataLoader sessionById,
21-
CancellationToken cancellationToken) =>
22-
new SessionAttendeeCheckIn(attendeeId, sessionId);
19+
[EventMessage] int attendeeId)
20+
=> new(attendeeId, sessionId);
2321

2422
public async ValueTask<ISourceStream<int>> SubscribeToOnAttendeeCheckedInAsync(
2523
int sessionId,
2624
[Service] ITopicEventReceiver eventReceiver,
27-
CancellationToken cancellationToken) =>
28-
await eventReceiver.SubscribeAsync<string, int>(
25+
CancellationToken cancellationToken)
26+
=> await eventReceiver.SubscribeAsync<string, int>(
2927
"OnAttendeeCheckedIn_" + sessionId, cancellationToken);
3028
}
3129
}

code/complete/GraphQL/Attendees/CheckInAttendeePayload.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace ConferencePlanner.GraphQL.Attendees
88
{
99
public class CheckInAttendeePayload : AttendeePayloadBase
1010
{
11-
private int? _sessionId;
11+
private readonly int? _sessionId;
1212

1313
public CheckInAttendeePayload(Attendee attendee, int sessionId)
1414
: base(attendee)

code/complete/GraphQL/Attendees/SessionAttendeeCheckIn.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ public SessionAttendeeCheckIn(int attendeeId, int sessionId)
2626
[UseApplicationDbContext]
2727
public async Task<int> CheckInCountAsync(
2828
[ScopedService] ApplicationDbContext context,
29-
CancellationToken cancellationToken) =>
30-
await context.Sessions
29+
CancellationToken cancellationToken)
30+
=> await context.Sessions
3131
.Where(session => session.Id == SessionId)
3232
.SelectMany(session => session.SessionAttendees)
3333
.CountAsync(cancellationToken);
3434

3535
public Task<Attendee> GetAttendeeAsync(
3636
AttendeeByIdDataLoader attendeeById,
37-
CancellationToken cancellationToken) =>
38-
attendeeById.LoadAsync(AttendeeId, cancellationToken);
37+
CancellationToken cancellationToken)
38+
=> attendeeById.LoadAsync(AttendeeId, cancellationToken);
3939

4040
public Task<Session> GetSessionAsync(
4141
SessionByIdDataLoader sessionById,
42-
CancellationToken cancellationToken) =>
43-
sessionById.LoadAsync(AttendeeId, cancellationToken);
42+
CancellationToken cancellationToken)
43+
=> sessionById.LoadAsync(AttendeeId, cancellationToken);
4444
}
4545
}

code/complete/GraphQL/Extensions/ObjectFieldDescriptorExtensions.cs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
1-
using Microsoft.EntityFrameworkCore;
2-
using Microsoft.Extensions.DependencyInjection;
31
using HotChocolate.Types;
42

53
namespace ConferencePlanner.GraphQL
64
{
75
public static class ObjectFieldDescriptorExtensions
86
{
9-
public static IObjectFieldDescriptor UseDbContext<TDbContext>(
10-
this IObjectFieldDescriptor descriptor)
11-
where TDbContext : DbContext
12-
{
13-
return descriptor.UseScopedService<TDbContext>(
14-
create: s => s.GetRequiredService<IDbContextFactory<TDbContext>>().CreateDbContext(),
15-
disposeAsync: (s, c) => c.DisposeAsync());
16-
}
17-
187
public static IObjectFieldDescriptor UseUpperCase(
198
this IObjectFieldDescriptor descriptor)
209
{
2110
// TODO : we need a better API for the user.
2211
descriptor.Extend().Definition.ResultConverters.Add(
23-
new((context, result) =>
12+
new((_, result) =>
2413
{
2514
if (result is string s)
2615
{
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
using System.Reflection;
21
using ConferencePlanner.GraphQL.Data;
3-
using HotChocolate.Types;
4-
using HotChocolate.Types.Descriptors;
2+
using HotChocolate.Data;
53

64
namespace ConferencePlanner.GraphQL
75
{
8-
public class UseApplicationDbContextAttribute : ObjectFieldDescriptorAttribute
6+
public class UseApplicationDbContextAttribute : UseDbContextAttribute
97
{
10-
public override void OnConfigure(
11-
IDescriptorContext context,
12-
IObjectFieldDescriptor descriptor,
13-
MemberInfo member)
8+
public UseApplicationDbContextAttribute() : base(typeof(ApplicationDbContext))
149
{
15-
descriptor.UseDbContext<ApplicationDbContext>();
1610
}
1711
}
1812
}

code/complete/GraphQL/Extensions/UseUpperCaseAttribute.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ public override void OnConfigure(
1010
IDescriptorContext context,
1111
IObjectFieldDescriptor descriptor,
1212
MemberInfo member)
13-
{
14-
descriptor.UseUpperCase();
15-
}
13+
=> descriptor.UseUpperCase();
1614
}
1715
}

code/complete/GraphQL/GraphQL.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<ItemGroup>
1515
<PackageReference Include="HotChocolate.AspNetCore" Version="12.0.0-rc.8" />
16-
<PackageReference Include="HotChocolate.Data" Version="12.0.0-rc.8" />
16+
<PackageReference Include="HotChocolate.Data.EntityFramework" Version="12.0.0-rc.8" />
1717
<PackageReference Include="HotChocolate.PersistedQueries.FileSystem" Version="12.0.0-rc.8" />
1818
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0-preview.7.21378.4" />
1919
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0-preview.7.21378.4">

code/complete/GraphQL/Imports/DataImporter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,22 @@ public class DataImporter
1212
{
1313
public async Task LoadDataAsync(ApplicationDbContext db)
1414
{
15-
using var stream = File.OpenRead("Imports/NDC_London_2019.json");
15+
await using var stream = File.OpenRead("Imports/NDC_London_2019.json");
1616
using var reader = new JsonTextReader(new StreamReader(stream));
1717

1818
JArray conference = await JArray.LoadAsync(reader);
1919
var speakers = new Dictionary<string, Speaker>();
2020

21-
foreach (JObject conferenceDay in conference)
21+
foreach (var conferenceDay in conference)
2222
{
23-
foreach (JObject roomData in conferenceDay["rooms"]!)
23+
foreach (var roomData in conferenceDay["rooms"]!)
2424
{
2525
var track = new Track
2626
{
2727
Name = roomData["name"]!.ToString()
2828
};
2929

30-
foreach (JObject sessionData in roomData["sessions"]!)
30+
foreach (var sessionData in roomData["sessions"]!)
3131
{
3232
var session = new Session
3333
{
@@ -39,7 +39,7 @@ public async Task LoadDataAsync(ApplicationDbContext db)
3939

4040
track.Sessions.Add(session);
4141

42-
foreach (JObject speakerData in sessionData["speakers"]!)
42+
foreach (var speakerData in sessionData["speakers"]!)
4343
{
4444
string id = speakerData["id"]!.ToString();
4545

0 commit comments

Comments
 (0)