Skip to content

Commit

Permalink
Fixing concurrent execution of fields resolution (#3119)
Browse files Browse the repository at this point in the history
Fixes #3029
  • Loading branch information
sebastienros authored Jan 31, 2019
1 parent 1bd7996 commit f80de17
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using GraphQL;
using GraphQL.Execution;
using GraphQL.Language.AST;
using System;

namespace OrchardCore.Apis.GraphQL.Services
{
/// <summary>
/// Defines a custom execution strategy for queries such that async lambdas are not executed in parallel.
/// c.f. https://github.com/OrchardCMS/OrchardCore/issues/3029
/// </summary>
public class SerialDocumentExecuter : DocumentExecuter
{
private static IExecutionStrategy ParallelExecutionStrategy = new ParallelExecutionStrategy();
private static IExecutionStrategy SerialExecutionStrategy = new SerialExecutionStrategy();
private static IExecutionStrategy SubscriptionExecutionStrategy = new SubscriptionExecutionStrategy();

protected override IExecutionStrategy SelectExecutionStrategy(ExecutionContext context)
{
switch (context.Operation.OperationType)
{
case OperationType.Query:
return SerialExecutionStrategy;

case OperationType.Mutation:
return SerialExecutionStrategy;

case OperationType.Subscription:
return SubscriptionExecutionStrategy;

default:
throw new InvalidOperationException($"Unexpected OperationType {context.Operation.OperationType}");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public Startup(IShellConfiguration configuration,
public override void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IDependencyResolver, RequestServicesDependencyResolver>();
services.AddSingleton<IDocumentExecuter, DocumentExecuter>();
services.AddSingleton<IDocumentExecuter, SerialDocumentExecuter>();
services.AddSingleton<IDocumentWriter, DocumentWriter>();

services.AddScoped<ISchemaFactory, SchemaService>();
Expand Down

0 comments on commit f80de17

Please sign in to comment.