Skip to content

Commit faac5cd

Browse files
Merge pull request #168 from AntonioFalcao/feature/graphql-4
GraphQL 4
2 parents 44b9120 + b371fad commit faac5cd

70 files changed

Lines changed: 765 additions & 755 deletions

File tree

Some content is hidden

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

Directory.Build.props

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<Project>
2+
23
<PropertyGroup Label="Common properties">
34
<TargetFramework>net5.0</TargetFramework>
45
<LangVersion>9</LangVersion>
@@ -7,23 +8,29 @@
78
<PropertyGroup Label="Packages dependency versions">
89

910
<!--Microsoft-->
10-
<Microsoft_DependencyInjection_Version>5.0.0</Microsoft_DependencyInjection_Version>
11+
<Microsoft_Extensions_Version>6.0.0-preview.2.21154.6</Microsoft_Extensions_Version>
1112

1213
<!--EF Core-->
13-
<Microsoft_EntityFrameworkCore_Version>6.0.0-preview.1.21102.2</Microsoft_EntityFrameworkCore_Version>
14+
<Microsoft_EntityFrameworkCore_Version>6.0.0-preview.2.21154.2</Microsoft_EntityFrameworkCore_Version>
15+
<Microsoft_EntityFrameworkCore_DependencyInjection_Version>6.0.0-preview.2.21154.6</Microsoft_EntityFrameworkCore_DependencyInjection_Version>
16+
<Microsoft_HealthChecks_EntityFrameworkCore_Version>6.0.0-preview.2.21154.6</Microsoft_HealthChecks_EntityFrameworkCore_Version>
1417

1518
<!--GraphQL-->
16-
<GraphQL_Server_Version>4.4.1</GraphQL_Server_Version>
19+
<GraphQL_Server_Version>5.0.0</GraphQL_Server_Version>
1720
<GraphQL_Client_Version>3.2.2</GraphQL_Client_Version>
18-
<GraphQL_Version>3.3.2</GraphQL_Version>
21+
<GraphQL_Version>4.1.0</GraphQL_Version>
1922

2023
<!--AutoMapper-->
2124
<AutoMapper_DependencyInjection_Version>8.1.1</AutoMapper_DependencyInjection_Version>
2225
<AutoMapper_Version>10.1.1</AutoMapper_Version>
2326

27+
<!--HealthChecks-->
28+
<HealthChecks_Version>5.0.1</HealthChecks_Version>
29+
2430
<!--Others-->
25-
<FluentValidation_Version>9.5.3</FluentValidation_Version>
31+
<FluentValidation_Version>10.0.0.0-preview4</FluentValidation_Version>
2632
<Scrutor_Version>3.3.0</Scrutor_Version>
2733

2834
</PropertyGroup>
35+
2936
</Project>

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ query all {
443443
}
444444
}
445445

446-
query byid($productId: ID!) {
446+
query byid($productId: Guid!) {
447447
product(id: $productId) {
448448
id
449449
name
@@ -475,7 +475,7 @@ HTTP BODY
475475
}
476476
}
477477
}
478-
query byid($productId: ID!) {
478+
query byid($productId: Guid!) {
479479
product(id: $productId) {
480480
id
481481
name

src/Dotnet5.GraphQL3.CrossCutting/Dotnet5.GraphQL3.CrossCutting.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<ItemGroup>
33
<PackageReference Include="FluentValidation" Version="$(FluentValidation_Version)"/>
44
<PackageReference Include="GraphQL" Version="$(GraphQL_Version)"/>
5-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(Microsoft_DependencyInjection_Version)"/>
6-
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="5.0.0"/>
5+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(Microsoft_Extensions_Version)"/>
6+
<PackageReference Include="Microsoft.Extensions.DependencyModel" Version="$(Microsoft_Extensions_Version)"/>
77
</ItemGroup>
88
</Project>

src/Dotnet5.GraphQL3.CrossCutting/Notifications/NotificationContext.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,29 @@ namespace Dotnet5.GraphQL3.CrossCutting.Notifications
88
{
99
public class NotificationContext : INotificationContext
1010
{
11-
private readonly List<Notification> _notifications;
12-
13-
public NotificationContext()
14-
{
15-
_notifications = new List<Notification>();
16-
}
11+
private List<Notification> _notifications { get; } = new();
1712

1813
private IEnumerable<ExecutionError> _executionErrors
19-
=> _notifications.Select(notification => new ExecutionError(notification.Message));
14+
=> _notifications.Select<Notification, ExecutionError>(notification
15+
=> new(notification.Message));
2016

2117
public ExecutionErrors ExecutionErrors
2218
{
2319
get
2420
{
25-
var executionErrors = new ExecutionErrors();
21+
ExecutionErrors executionErrors = new();
2622
executionErrors.AddRange(_executionErrors);
2723
return executionErrors;
2824
}
2925
}
3026

31-
public IReadOnlyList<Notification> Notifications => _notifications;
32-
public bool HasNotifications => _notifications.Any();
27+
public IReadOnlyList<Notification> Notifications
28+
=> _notifications;
29+
public bool HasNotifications
30+
=> _notifications.Any();
3331

3432
public void AddNotification(string message, string key = default)
35-
=> _notifications.Add(new Notification(key, message));
33+
=> _notifications.Add(new(key, message));
3634

3735
public void AddNotification(Notification notification)
3836
=> _notifications.Add(notification);
@@ -41,10 +39,8 @@ public void AddNotifications(IEnumerable<Notification> notifications)
4139
=> _notifications.AddRange(notifications);
4240

4341
public void AddNotifications(ValidationResult validationResult)
44-
{
45-
foreach (var error in validationResult.Errors)
46-
AddNotification(error.ErrorMessage, error.ErrorCode);
47-
}
42+
=> validationResult.Errors.ToList().ForEach(failure
43+
=> AddNotification(failure.ErrorMessage, failure.ErrorCode));
4844

4945
public void AddNotificationWithId(string message, object id)
5046
=> AddNotification(string.Format(message, id));

src/Dotnet5.GraphQL3.Domain.Abstractions/Dotnet5.GraphQL3.Domain.Abstractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<ItemGroup>
33
<PackageReference Include="FluentValidation" Version="$(FluentValidation_Version)"/>
4-
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(Microsoft_DependencyInjection_Version)"/>
4+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(Microsoft_Extensions_Version)"/>
55
<PackageReference Include="Scrutor" Version="$(Scrutor_Version)"/>
66
</ItemGroup>
77
<ItemGroup>

src/Dotnet5.GraphQL3.Domain.Abstractions/Entities/Entity.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.ComponentModel.DataAnnotations.Schema;
23
using System.Linq;
34
using FluentValidation;
@@ -17,15 +18,25 @@ public bool IsValid
1718
[NotMapped]
1819
public ValidationResult ValidationResult { get; private set; }
1920

20-
protected bool OnValidate<TEntity>(TEntity entity, AbstractValidator<TEntity> validator)
21+
protected bool OnValidate<TValidator, TEntity>(TEntity entity, TValidator validator)
22+
where TValidator : AbstractValidator<TEntity>
23+
where TEntity : Entity<TId>
2124
{
2225
ValidationResult = validator.Validate(entity);
2326
return IsValid;
2427
}
2528

29+
protected bool OnValidate<TValidator, TEntity>(TEntity entity, TValidator validator, Func<AbstractValidator<TEntity>, TEntity, ValidationResult> validation)
30+
where TValidator : AbstractValidator<TEntity>
31+
where TEntity : Entity<TId>
32+
{
33+
ValidationResult = validation(validator, entity);
34+
return IsValid;
35+
}
36+
2637
protected void AddError(string errorMessage, ValidationResult validationResult = default)
2738
{
28-
ValidationResult.Errors.Add(new ValidationFailure(default, errorMessage));
39+
ValidationResult.Errors.Add(new(default, errorMessage));
2940
validationResult?.Errors.ToList().ForEach(failure => ValidationResult.Errors.Add(failure));
3041
}
3142

src/Dotnet5.GraphQL3.Repositories.Abstractions/IRepository.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ PagedResult<TResult> GetAllProjections<TResult>(
4343
Expression<Func<TEntity, bool>> predicate = default,
4444
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = default,
4545
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> include = default,
46-
bool asTracking = default);
46+
bool asTracking = default)
47+
where TResult : class;
4748

4849
Task<PagedResult<TEntity>> GetAllAsync(
4950
PageParams pageParams,
@@ -60,6 +61,7 @@ Task<PagedResult<TResult>> GetAllProjectionsAsync<TResult>(
6061
Expression<Func<TEntity, bool>> predicate = default,
6162
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = default,
6263
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> include = default,
63-
bool asTracking = default);
64+
bool asTracking = default)
65+
where TResult : class;
6466
}
6567
}

src/Dotnet5.GraphQL3.Repositories.Abstractions/Pages/PagedResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
namespace Dotnet5.GraphQL3.Repositories.Abstractions.Pages
88
{
9-
public class PagedResult<T>
9+
public class PagedResult<T>
10+
where T : class
1011
{
1112
private readonly IReadOnlyCollection<T> _items;
1213
private readonly int _index;

src/Dotnet5.GraphQL3.Repositories.Abstractions/Repository.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public PagedResult<TResult> GetAllProjections<TResult>(
129129
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = default,
130130
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> include = default,
131131
bool asTracking = default)
132+
where TResult : class
132133
{
133134
var query = asTracking ? _dbSet.AsTracking() : _dbSet.AsNoTrackingWithIdentityResolution();
134135

@@ -166,6 +167,7 @@ public Task<PagedResult<TResult>> GetAllProjectionsAsync<TResult>(
166167
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = default,
167168
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> include = default,
168169
bool asTracking = default)
170+
where TResult : class
169171
{
170172
var query = asTracking ? _dbSet.AsTracking() : _dbSet.AsNoTrackingWithIdentityResolution();
171173

src/Dotnet5.GraphQL3.Repositories.Abstractions/UnitsOfWork/UnitOfWork.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ public UnitOfWork(DbContext dbContext)
2121
public IDbContextTransaction BeginTransaction()
2222
=> _database.BeginTransaction();
2323

24-
public async Task<IDbContextTransaction> BeginTransactionAsync(CancellationToken cancellationToken)
25-
=> await _database.BeginTransactionAsync(cancellationToken);
24+
public Task<IDbContextTransaction> BeginTransactionAsync(CancellationToken cancellationToken)
25+
=> _database.BeginTransactionAsync(cancellationToken);
2626

2727
public bool SaveChanges()
2828
=> _dbContext.SaveChanges(true) > default(int);
@@ -33,14 +33,14 @@ public async Task<bool> SaveChangesAsync(CancellationToken cancellationToken)
3333
public void CommitTransaction()
3434
=> _database.CommitTransaction();
3535

36-
public async Task CommitTransactionAsync(CancellationToken cancellationToken)
37-
=> await _database.CommitTransactionAsync(cancellationToken);
36+
public Task CommitTransactionAsync(CancellationToken cancellationToken)
37+
=> _database.CommitTransactionAsync(cancellationToken);
3838

3939
public void RollbackTransaction()
4040
=> _database.RollbackTransaction();
4141

42-
public async Task RollbackTransactionAsync(CancellationToken cancellationToken)
43-
=> await _database.RollbackTransactionAsync(cancellationToken);
42+
public Task RollbackTransactionAsync(CancellationToken cancellationToken)
43+
=> _database.RollbackTransactionAsync(cancellationToken);
4444

4545
public void Dispose()
4646
{

0 commit comments

Comments
 (0)