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

Fix parallel access to session from GQL fields #17332

Merged
merged 1 commit into from
Jan 13, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@

namespace OrchardCore.Apis.GraphQL.Resolvers;

public class LockedAsyncFieldResolver<TReturnType> : FuncFieldResolver<TReturnType>
public class LockedAsyncFieldResolver<TReturnType> : IFieldResolver
{
public LockedAsyncFieldResolver(Func<IResolveFieldContext, ValueTask<TReturnType>> resolver) : base(resolver)
{
private readonly Func<IResolveFieldContext, ValueTask<TReturnType>> _resolver;

public LockedAsyncFieldResolver(Func<IResolveFieldContext, ValueTask<TReturnType>> resolver)
{
ArgumentNullException.ThrowIfNull(resolver);
_resolver = resolver;
}

public new async ValueTask<object> ResolveAsync(IResolveFieldContext context)
public async ValueTask<object> ResolveAsync(IResolveFieldContext context)
{
var graphContext = (GraphQLUserContext)context.UserContext;
await graphContext.ExecutionContextLock.WaitAsync();

try
{
return await base.ResolveAsync(context);
return await _resolver(context).ConfigureAwait(false);
gvkries marked this conversation as resolved.
Show resolved Hide resolved
}
finally
{
Expand All @@ -26,20 +29,24 @@ public LockedAsyncFieldResolver(Func<IResolveFieldContext, ValueTask<TReturnType
}
}

public class LockedAsyncFieldResolver<TSourceType, TReturnType> : FuncFieldResolver<TSourceType, TReturnType>
public class LockedAsyncFieldResolver<TSourceType, TReturnType> : IFieldResolver
{
public LockedAsyncFieldResolver(Func<IResolveFieldContext<TSourceType>, ValueTask<TReturnType>> resolver) : base(resolver)
private readonly Func<IResolveFieldContext<TSourceType>, ValueTask<TReturnType>> _resolver;

public LockedAsyncFieldResolver(Func<IResolveFieldContext<TSourceType>, ValueTask<TReturnType>> resolver)
{
ArgumentNullException.ThrowIfNull(resolver);
_resolver = resolver;
}

public new async Task<object> ResolveAsync(IResolveFieldContext context)
public async ValueTask<object> ResolveAsync(IResolveFieldContext context)
{
var graphContext = (GraphQLUserContext)context.UserContext;
await graphContext.ExecutionContextLock.WaitAsync();

try
{
return await base.ResolveAsync(context);
return await _resolver(context.As<TSourceType>()).ConfigureAwait(false);
}
finally
{
Expand Down