Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c668be4
commit a7fa8a0
Showing
15 changed files
with
177 additions
and
15 deletions.
There are no files selected for viewing
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
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
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
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
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
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,18 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
/// <summary> | ||
/// Defines request middleware that can be added to the GraphQL request pipeline. | ||
/// </summary> | ||
public interface IRequestMiddleware | ||
{ | ||
/// <summary> | ||
/// Request handling method. | ||
/// </summary> | ||
/// <param name="context">The <see cref="IRequestContext"/> for the request.</param> | ||
/// <param name="next">The delegate representing the remaining middleware in the request pipeline.</param> | ||
/// <returns>A <see cref="Task"/> that represents the execution of this middleware.</returns> | ||
Task InvokeAsync(IRequestContext context, RequestDelegate next); | ||
} | ||
} |
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,16 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
internal sealed class MutationExecutor | ||
: IOperationExecutor | ||
{ | ||
public Task<IExecutionResult> ExecuteAsync( | ||
IOperationContext executionContext, | ||
CancellationToken cancellationToken) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/HotChocolate/Core/src/Execution/Properties/InternalsVisibleTo.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,4 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("HotChocolate.Execution.Tests")] | ||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] |
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,16 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
internal sealed class QueryExecutor | ||
: IOperationExecutor | ||
{ | ||
public Task<IExecutionResult> ExecuteAsync( | ||
IOperationContext executionContext, | ||
CancellationToken cancellationToken) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
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,11 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
/// <summary> | ||
/// A function that can process a GraphQL request. | ||
/// </summary> | ||
/// <param name="context">The <see cref="IRequestContext"/> for the request.</param> | ||
/// <returns>A task that represents the completion of request processing.</returns> | ||
public delegate Task RequestDelegate(IRequestContext context); | ||
} |
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 |
---|---|---|
@@ -1,8 +1,7 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
/// <summary> | ||
/// Defines request middleware that can be added to the GraphQL request pipeline. | ||
/// </summary> | ||
public delegate RequestDelegate RequestMiddleware(RequestDelegate next); | ||
|
||
public delegate Task RequestDelegate(IRequestContext context); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/HotChocolate/Core/src/Execution/SubscriptionExecutor.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,16 @@ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
internal sealed class SubscriptionExecutor | ||
: IOperationExecutor | ||
{ | ||
public Task<IExecutionResult> ExecuteAsync( | ||
IOperationContext executionContext, | ||
CancellationToken cancellationToken) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/HotChocolate/Core/src/Execution/Utilities/ClassMiddlewareFactory.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,55 @@ | ||
using System; | ||
using HotChocolate.Utilities; | ||
|
||
namespace HotChocolate.Execution.Utilities | ||
{ | ||
internal static class ClassMiddlewareFactory | ||
{ | ||
internal static RequestMiddleware Create<TMiddleware>() | ||
where TMiddleware : class | ||
{ | ||
return next => | ||
{ | ||
MiddlewareFactory<TMiddleware, RequestDelegate> factory = | ||
MiddlewareActivator.CompileFactory<TMiddleware, RequestDelegate>(); | ||
return CreateDelegate((s, n) => factory(s, n), next); | ||
}; | ||
} | ||
|
||
internal static RequestMiddleware Create<TMiddleware>( | ||
Func<IServiceProvider, RequestDelegate, TMiddleware> factory) | ||
where TMiddleware : class | ||
{ | ||
return next => CreateDelegate(factory, next); | ||
} | ||
|
||
internal static RequestDelegate CreateDelegate<TMiddleware>( | ||
Func<IServiceProvider, RequestDelegate, TMiddleware> factory, | ||
RequestDelegate next) | ||
where TMiddleware : class | ||
{ | ||
object sync = new object(); | ||
TMiddleware? middleware = null; | ||
|
||
ClassQueryDelegate<TMiddleware, IRequestContext> compiled = | ||
MiddlewareActivator.CompileMiddleware<TMiddleware, IRequestContext>(); | ||
|
||
return context => | ||
{ | ||
if (middleware == null) | ||
{ | ||
lock (sync) | ||
{ | ||
if (middleware == null) | ||
{ | ||
middleware = factory(context.Services, next); | ||
} | ||
} | ||
} | ||
return compiled(context, context.Services, middleware); | ||
}; | ||
} | ||
} | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/HotChocolate/Core/test/Execution.Tests/Utilities/ClassMiddlewareFactoryTests.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,26 @@ | ||
using System.Threading.Tasks; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace HotChocolate.Execution.Utilities | ||
{ | ||
public class ClassMiddlewareFactoryTests | ||
{ | ||
[Fact] | ||
public void Create_Middleware_From_Class_That_Implements_IRequestMiddleware() | ||
{ | ||
RequestMiddleware middleware = | ||
ClassMiddlewareFactory.Create<CustomMiddlewareThatImplementsInterface>(); | ||
var contextMock = new Mock<IRequestContext>(); | ||
middleware.Invoke(c => Task.CompletedTask).Invoke(contextMock.Object); | ||
} | ||
|
||
public class CustomMiddlewareThatImplementsInterface : IRequestMiddleware | ||
{ | ||
public Task InvokeAsync(IRequestContext context, RequestDelegate next) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} | ||
} | ||
} |