-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing concurrent execution of fields resolution (#3119)
Fixes #3029
- Loading branch information
1 parent
1bd7996
commit f80de17
Showing
2 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/Services/SerialDocumentExecuter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters