Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove net7.0 support #6

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 18 additions & 31 deletions src/Fluss.HotChocolate/AddExtensionMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,20 @@

namespace Fluss.HotChocolate;

public class AddExtensionMiddleware
public class AddExtensionMiddleware(
RequestDelegate next,
IServiceProvider rootServiceProvider,
ILogger<AddExtensionMiddleware> logger)
{
private const string SubsequentRequestMarker = nameof(AddExtensionMiddleware) + ".subsequentRequestMarker";

private readonly RequestDelegate _next;

private readonly IServiceProvider _rootServiceProvider;
private readonly ILogger<AddExtensionMiddleware> _logger;

public AddExtensionMiddleware(
RequestDelegate next,
IServiceProvider rootServiceProvider,
ILogger<AddExtensionMiddleware> logger
)
{
_next = next ?? throw new ArgumentNullException(nameof(next));
_rootServiceProvider = rootServiceProvider;
_logger = logger;
}
private readonly RequestDelegate _next = next ?? throw new ArgumentNullException(nameof(next));

public async ValueTask InvokeAsync(IRequestContext context)
{
await _next.Invoke(context);

if (!context.ContextData.ContainsKey(nameof(UnitOfWork)))
if (!context.ContextData.TryGetValue(nameof(UnitOfWork), out var unitOfWork))
{
return;
}
Expand All @@ -50,7 +39,7 @@ public async ValueTask InvokeAsync(IRequestContext context)
if (context.Result is QueryResult subsequentQueryResult)
{
context.Result = QueryResultBuilder.FromResult(subsequentQueryResult).AddContextData(nameof(UnitOfWork),
context.ContextData[nameof(UnitOfWork)]).Create();
unitOfWork).Create();
}

return;
Expand All @@ -69,12 +58,12 @@ private async IAsyncEnumerable<IQueryResult> LiveResults(IReadOnlyDictionary<str
{
yield return firstResult;

using var serviceScope = _rootServiceProvider.CreateScope();
using var serviceScope = rootServiceProvider.CreateScope();
var serviceProvider = serviceScope.ServiceProvider;

if (contextData == null)
{
_logger.LogWarning("Trying to add live results but {ContextData} is null!", nameof(contextData));
logger.LogWarning("Trying to add live results but {ContextData} is null!", nameof(contextData));
yield break;
}

Expand All @@ -83,26 +72,24 @@ private async IAsyncEnumerable<IQueryResult> LiveResults(IReadOnlyDictionary<str
var foundSocketSession = contextData.TryGetValue(nameof(ISocketSession), out var contextSocketSession); // as ISocketSession
var foundOperationId = contextData.TryGetValue("HotChocolate.Execution.Transport.OperationSessionId", out var operationId); // as string

if (isWebsocket && (!foundSocketSession || !foundOperationId))
switch (isWebsocket)
{
_logger.LogWarning("Trying to add live results but {SocketSession} or {OperationId} is not present in context!", nameof(contextSocketSession), nameof(operationId));
yield break;
}

if (isWebsocket && contextSocketSession is not ISocketSession)
{
_logger.LogWarning("{ContextSocketSession} key present in context but not an {ISocketSession}!", contextSocketSession?.GetType().FullName, nameof(ISocketSession));
yield break;
case true when !foundSocketSession || !foundOperationId:
logger.LogWarning("Trying to add live results but {SocketSession} or {OperationId} is not present in context!", nameof(contextSocketSession), nameof(operationId));
yield break;
case true when contextSocketSession is not ISocketSession:
logger.LogWarning("{ContextSocketSession} key present in context but not an {ISocketSession}!", contextSocketSession?.GetType().FullName, nameof(ISocketSession));
yield break;
}

while (true)
{
if (contextData == null || !contextData.ContainsKey(nameof(UnitOfWork)))
if (contextData == null || !contextData.TryGetValue(nameof(UnitOfWork), out var value))
{
break;
}

if (contextData[nameof(UnitOfWork)] is not UnitOfWork unitOfWork)
if (value is not UnitOfWork unitOfWork)
{
break;
}
Expand Down
76 changes: 11 additions & 65 deletions src/Fluss.HotChocolate/AutoGenerateSchema/AutoGenerateSchema.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.ComponentModel;
using System.Reflection;
using HotChocolate.Data.Filters;
using HotChocolate.Execution.Configuration;
using HotChocolate.Language;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -45,20 +44,16 @@ private static Type GetStronglyTypedIdTypeForType(Type type)
}

throw new ArgumentException(
$"Could not find Type converter for strongly typed IDs with backing type {backingType!.Name}");
$"Could not find Type converter for strongly typed IDs with backing type {backingType.Name}");
}
}

public abstract class StronglyTypedIdType<TId, TScalarType, TCLRType, TNodeType> : ScalarType<TId, TNodeType>
where TId : struct where TScalarType : ScalarType<TCLRType, TNodeType> where TNodeType : IValueNode
public abstract class StronglyTypedIdType<TId, TScalarType, TCLRType, TNodeType>(TScalarType scalarType)
: ScalarType<TId, TNodeType>(typeof(TId).Name)
where TId : struct
where TScalarType : ScalarType<TCLRType, TNodeType>
where TNodeType : IValueNode
{
private readonly TScalarType scalarType;

protected StronglyTypedIdType(TScalarType scalarType) : base(typeof(TId).Name)
{
this.scalarType = scalarType;
}

protected override TId ParseLiteral(TNodeType valueSyntax)
{
var guid = (TCLRType)scalarType.ParseLiteral(valueSyntax)!;
Expand Down Expand Up @@ -98,58 +93,9 @@ public override bool TrySerialize(object? runtimeValue, out object? resultValue)
}
}

public class StronglyTypedGuidIdType<TId> : StronglyTypedIdType<TId, UuidType, Guid, StringValueNode> where TId : struct
{
public StronglyTypedGuidIdType() : base(new UuidType('D')) { }
}

public class StronglyTypedLongIdType<TId> : StronglyTypedIdType<TId, LongType, long, IntValueNode> where TId : struct
{
public StronglyTypedLongIdType() : base(new LongType()) { }
}

public class StronglyTypedIdFilterConventionExtension<TAssemblyReference> : FilterConventionExtension
{
protected override void Configure(IFilterConventionDescriptor descriptor)
{
base.Configure(descriptor);

var typesToGenerateFor = typeof(TAssemblyReference).Assembly.GetTypes().Where(t =>
t.IsValueType && t.CustomAttributes.Any(a =>
a.AttributeType == typeof(TypeConverterAttribute)));

public class StronglyTypedGuidIdType<TId>()
: StronglyTypedIdType<TId, UuidType, Guid, StringValueNode>(new UuidType('D'))
where TId : struct;

foreach (var type in typesToGenerateFor)
{
var filterInputType = typeof(StronglyTypedGuidIdFilterInput<>).MakeGenericType(type);
var nullableType = typeof(Nullable<>).MakeGenericType(type);
descriptor.BindRuntimeType(type, filterInputType);
descriptor.BindRuntimeType(nullableType, filterInputType);
}
}
}

public class StronglyTypedGuidIdFilterInput<TId> : StringOperationFilterInputType
{
/*public override bool TrySerialize(object? runtimeValue, out object? resultValue) {
if (runtimeValue is TId id) {
resultValue = id.ToString();
return true;
}

resultValue = null;
return false;
}

public override bool TryDeserialize(object? resultValue, out object? runtimeValue) {
var canParseGuid = Guid.TryParse(resultValue?.ToString(), out var parsedGuid);
if (!canParseGuid) {
runtimeValue = null;
return false;
}

var tId = Activator.CreateInstance(typeof(TId), parsedGuid);
runtimeValue = tId;
return true;
}*/
}
public class StronglyTypedLongIdType<TId>() : StronglyTypedIdType<TId, LongType, long, IntValueNode>(new LongType())
where TId : struct;
11 changes: 6 additions & 5 deletions src/Fluss.HotChocolate/Fluss.HotChocolate.csproj
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0; net7.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HotChocolate" Version="13.5.1" />
<PackageReference Include="HotChocolate.AspNetCore" Version="13.5.1" />
<PackageReference Include="HotChocolate.Data" Version="13.5.1" />
<PackageReference Include="HotChocolate" Version="13.5.1"/>
<PackageReference Include="HotChocolate.AspNetCore" Version="13.5.1"/>
<PackageReference Include="HotChocolate.Data" Version="13.5.1"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Fluss\Fluss.csproj" />
<ProjectReference Include="..\Fluss\Fluss.csproj"/>
</ItemGroup>

</Project>
6 changes: 3 additions & 3 deletions src/Fluss.HotChocolate/NewEventNotifier.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using Fluss.Events;
using Fluss.Extensions;

namespace Fluss.HotChocolate;

public class NewEventNotifier
{
private long _knownVersion;
private readonly List<(long startedAtVersion, SemaphoreSlim semaphoreSlim)> _listeners = new();
private readonly List<(long startedAtVersion, SemaphoreSlim semaphoreSlim)> _listeners = [];
private readonly SemaphoreSlim _newEventAvailable = new(0);

public NewEventNotifier(IBaseEventRepository eventRepository)
{
_knownVersion = eventRepository.GetLatestVersion().GetResult();
_knownVersion = eventRepository.GetLatestVersion().AsTask().Result;
eventRepository.NewEvents += EventRepositoryOnNewEvents;

_ = Task.Run(async () =>
Expand Down Expand Up @@ -41,6 +40,7 @@ public NewEventNotifier(IBaseEventRepository eventRepository)
}
}
}
// ReSharper disable once FunctionNeverReturns
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/Fluss.HotChocolate/NewTransientEventNotifier.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Fluss.Events.TransientEvents;
// ReSharper disable LoopCanBeConvertedToQuery

namespace Fluss.HotChocolate;

public class NewTransientEventNotifier
{
private readonly List<(long startedAtVersion, TaskCompletionSource<IEnumerable<TransientEventEnvelope>> task)> _listeners = new();
private readonly List<(long startedAtVersion, TaskCompletionSource<IEnumerable<TransientEventEnvelope>> task)> _listeners = [];
private readonly TransientEventAwareEventRepository _transientEventRepository;

private readonly SemaphoreSlim _newEventAvailable = new(0);
Expand Down Expand Up @@ -48,6 +49,7 @@ public NewTransientEventNotifier(TransientEventAwareEventRepository transientEve
}
}
}
// ReSharper disable once FunctionNeverReturns
});
}

Expand Down
12 changes: 2 additions & 10 deletions src/Fluss.HotChocolate/UnitOfWorkParameterExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,15 @@ public class UnitOfWorkParameterExpressionBuilder : IParameterExpressionBuilder

private static readonly MethodInfo ServiceUnitOfWorkMethod =
typeof(IPureResolverContext).GetMethods().First(
method => method.Name == nameof(IPureResolverContext.Service) &&
method.IsGenericMethod)
method => method is { Name: nameof(IPureResolverContext.Service), IsGenericMethod: true })
.MakeGenericMethod(typeof(UnitOfWork));

private static readonly MethodInfo GetValueOrDefaultMethod =
typeof(CollectionExtensions).GetMethods().First(m => m.Name == nameof(CollectionExtensions.GetValueOrDefault) && m.GetParameters().Length == 2);

private static readonly MethodInfo WithPrefilledVersionMethod =
typeof(UnitOfWork).GetMethods(BindingFlags.Instance | BindingFlags.Public)
.First(m => m.Name == nameof(UnitOfWork.WithPrefilledVersion));

private static readonly PropertyInfo ContextData =
typeof(IHasContextData).GetProperty(
nameof(IHasContextData.ContextData))!;

public bool CanHandle(ParameterInfo parameter) => typeof(UnitOfWork) == parameter.ParameterType
|| typeof(IUnitOfWork) == parameter.ParameterType;
|| typeof(IUnitOfWork) == parameter.ParameterType;

/*
* Produces something like this: context.GetOrSetGlobalState(
Expand Down
21 changes: 11 additions & 10 deletions src/Fluss.PostgreSQL/Fluss.PostgreSQL.csproj
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0; net7.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentMigrator.Runner" Version="3.3.2" />
<PackageReference Include="FluentMigrator.Runner.Postgres" Version="3.3.2" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageReference Include="Npgsql" Version="7.0.6" />
<PackageReference Include="Npgsql.Json.NET" Version="7.0.6" />
<PackageReference Include="FluentMigrator.Runner" Version="3.3.2"/>
<PackageReference Include="FluentMigrator.Runner.Postgres" Version="3.3.2"/>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0"/>
<PackageReference Include="Npgsql" Version="7.0.7"/>
<PackageReference Include="Npgsql.Json.NET" Version="7.0.7"/>
</ItemGroup>

<ItemGroup>
<Reference Include="OpenTelemetry.Api">
<HintPath>..\..\..\..\..\.nuget\packages\opentelemetry.api\1.6.0\lib\net6.0\OpenTelemetry.Api.dll</HintPath>
</Reference>
<Reference Include="OpenTelemetry.Api">
<HintPath>..\..\..\..\..\.nuget\packages\opentelemetry.api\1.6.0\lib\net6.0\OpenTelemetry.Api.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Fluss\Fluss.csproj" />
<ProjectReference Include="..\Fluss\Fluss.csproj"/>
</ItemGroup>

</Project>
Loading
Loading