Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Feb 17, 2024
1 parent 3658690 commit 162598b
Show file tree
Hide file tree
Showing 19 changed files with 242 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,27 @@

namespace HotChocolate.Execution.Pipeline;

internal sealed class DocumentCacheMiddleware(
RequestDelegate next,
[SchemaService] IExecutionDiagnosticEvents diagnosticEvents,
IDocumentCache documentCache,
IDocumentHashProvider documentHashProvider)
internal sealed class DocumentCacheMiddleware
{
private readonly RequestDelegate _next = next ??
throw new ArgumentNullException(nameof(next));
private readonly IExecutionDiagnosticEvents _diagnosticEvents = diagnosticEvents ??
throw new ArgumentNullException(nameof(diagnosticEvents));
private readonly IDocumentCache _documentCache = documentCache ??
throw new ArgumentNullException(nameof(documentCache));
private readonly IDocumentHashProvider _documentHashProvider = documentHashProvider ??
throw new ArgumentNullException(nameof(documentHashProvider));
private readonly RequestDelegate _next;
private readonly IExecutionDiagnosticEvents _diagnosticEvents;
private readonly IDocumentCache _documentCache;
private readonly IDocumentHashProvider _documentHashProvider;

private DocumentCacheMiddleware(RequestDelegate next,
[SchemaService] IExecutionDiagnosticEvents diagnosticEvents,
IDocumentCache documentCache,
IDocumentHashProvider documentHashProvider)
{
_next = next ??
throw new ArgumentNullException(nameof(next));
_diagnosticEvents = diagnosticEvents ??
throw new ArgumentNullException(nameof(diagnosticEvents));
_documentCache = documentCache ??
throw new ArgumentNullException(nameof(documentCache));
_documentHashProvider = documentHashProvider ??
throw new ArgumentNullException(nameof(documentHashProvider));
}

public async ValueTask InvokeAsync(IRequestContext context)
{
Expand Down Expand Up @@ -84,7 +91,14 @@ public static RequestCoreMiddleware Create()
var diagnosticEvents = core.SchemaServices.GetRequiredService<IExecutionDiagnosticEvents>();
var documentCache = core.Services.GetRequiredService<IDocumentCache>();
var documentHashProvider = core.Services.GetRequiredService<IDocumentHashProvider>();
var middleware = new DocumentCacheMiddleware(next, diagnosticEvents, documentCache, documentHashProvider);
var middleware = Create(next, diagnosticEvents, documentCache, documentHashProvider);
return context => middleware.InvokeAsync(context);
};

internal static DocumentCacheMiddleware Create(
RequestDelegate next,
IExecutionDiagnosticEvents diagnosticEvents,
IDocumentCache documentCache,
IDocumentHashProvider documentHashProvider)
=> new(next, diagnosticEvents, documentCache, documentHashProvider);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@

namespace HotChocolate.Execution.Pipeline;

internal sealed class DocumentParserMiddleware(
RequestDelegate next,
[SchemaService] IExecutionDiagnosticEvents diagnosticEvents,
IDocumentHashProvider documentHashProvider,
ParserOptions parserOptions)
internal sealed class DocumentParserMiddleware
{
private readonly RequestDelegate _next = next ??
throw new ArgumentNullException(nameof(next));
private readonly RequestDelegate _next;
private readonly IExecutionDiagnosticEvents _diagnosticEvents;
private readonly IDocumentHashProvider _documentHashProvider;
private readonly ParserOptions _parserOptions;

private readonly IExecutionDiagnosticEvents _diagnosticEvents = diagnosticEvents ??
throw new ArgumentNullException(nameof(diagnosticEvents));

private readonly IDocumentHashProvider _documentHashProvider = documentHashProvider ??
throw new ArgumentNullException(nameof(documentHashProvider));

private readonly ParserOptions _parserOptions = parserOptions ??
throw new ArgumentNullException(nameof(parserOptions));
private DocumentParserMiddleware(RequestDelegate next,
[SchemaService] IExecutionDiagnosticEvents diagnosticEvents,
IDocumentHashProvider documentHashProvider,
ParserOptions parserOptions)
{
_next = next ??
throw new ArgumentNullException(nameof(next));
_diagnosticEvents = diagnosticEvents ??
throw new ArgumentNullException(nameof(diagnosticEvents));
_documentHashProvider = documentHashProvider ??
throw new ArgumentNullException(nameof(documentHashProvider));
_parserOptions = parserOptions ??
throw new ArgumentNullException(nameof(parserOptions));
}

public async ValueTask InvokeAsync(IRequestContext context)
{
Expand Down Expand Up @@ -99,7 +103,14 @@ public static RequestCoreMiddleware Create()
var diagnosticEvents = core.SchemaServices.GetRequiredService<IExecutionDiagnosticEvents>();
var documentHashProvider = core.Services.GetRequiredService<IDocumentHashProvider>();
var parserOptions = core.Services.GetRequiredService<ParserOptions>();
var middleware = new DocumentParserMiddleware(next, diagnosticEvents, documentHashProvider, parserOptions);
var middleware = Create(next, diagnosticEvents, documentHashProvider, parserOptions);
return context => middleware.InvokeAsync(context);
};

internal static DocumentParserMiddleware Create(
RequestDelegate next,
[SchemaService] IExecutionDiagnosticEvents diagnosticEvents,
IDocumentHashProvider documentHashProvider,
ParserOptions parserOptions)
=> new(next, diagnosticEvents, documentHashProvider, parserOptions);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using HotChocolate.Execution.Instrumentation;
using HotChocolate.Language;
using HotChocolate.Validation;
using Microsoft.Extensions.DependencyInjection;
using static HotChocolate.WellKnownContextData;
using static HotChocolate.Execution.ErrorHelper;

namespace HotChocolate.Execution.Pipeline;

internal sealed class DocumentValidationMiddleware(
RequestDelegate next,
[SchemaService] IExecutionDiagnosticEvents diagnosticEvents,
IDocumentValidator documentValidator)
internal sealed class DocumentValidationMiddleware
{
private readonly RequestDelegate _next = next ??
throw new ArgumentNullException(nameof(next));
private readonly IExecutionDiagnosticEvents _diagnosticEvents = diagnosticEvents ??
throw new ArgumentNullException(nameof(diagnosticEvents));
private readonly IDocumentValidator _documentValidator = documentValidator ??
throw new ArgumentNullException(nameof(documentValidator));
private readonly RequestDelegate _next;
private readonly IExecutionDiagnosticEvents _diagnosticEvents;
private readonly IDocumentValidator _documentValidator;

private DocumentValidationMiddleware(
RequestDelegate next,
[SchemaService] IExecutionDiagnosticEvents diagnosticEvents,
IDocumentValidator documentValidator)
{
_next = next ??
throw new ArgumentNullException(nameof(next));
_diagnosticEvents = diagnosticEvents ??
throw new ArgumentNullException(nameof(diagnosticEvents));
_documentValidator = documentValidator ??
throw new ArgumentNullException(nameof(documentValidator));
}

public async ValueTask InvokeAsync(IRequestContext context)
{
Expand Down Expand Up @@ -80,14 +86,20 @@ await _documentValidator
await _next(context).ConfigureAwait(false);
}
}

public static RequestCoreMiddleware Create()
=> (core, next) =>
{
var diagnosticEvents = core.SchemaServices.GetRequiredService<IExecutionDiagnosticEvents>();
var documentValidatorFactory = core.Services.GetRequiredService<IDocumentValidatorFactory>();
var documentValidator = documentValidatorFactory.CreateValidator(core.SchemaName);
var middleware = new DocumentValidationMiddleware(next, diagnosticEvents, documentValidator);
var documentValidator = documentValidatorFactory.CreateValidator(core.SchemaName);
var middleware = Create(next, diagnosticEvents, documentValidator);
return context => middleware.InvokeAsync(context);
};
}

internal static DocumentValidationMiddleware Create(
RequestDelegate next,
[SchemaService] IExecutionDiagnosticEvents diagnosticEvents,
IDocumentValidator documentValidator)
=> new(next, diagnosticEvents, documentValidator);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

namespace HotChocolate.Execution.Pipeline;

internal sealed class ExceptionMiddleware(RequestDelegate next, [SchemaService] IErrorHandler errorHandler)
internal sealed class ExceptionMiddleware
{
private readonly RequestDelegate _next = next ??
throw new ArgumentNullException(nameof(next));
private readonly IErrorHandler _errorHandler = errorHandler ??
throw new ArgumentNullException(nameof(errorHandler));
private readonly RequestDelegate _next;
private readonly IErrorHandler _errorHandler;

private ExceptionMiddleware(RequestDelegate next, [SchemaService] IErrorHandler errorHandler)
{
_next = next ??
throw new ArgumentNullException(nameof(next));
_errorHandler = errorHandler ??
throw new ArgumentNullException(nameof(errorHandler));
}

public async ValueTask InvokeAsync(IRequestContext context)
{
Expand All @@ -34,12 +40,17 @@ public async ValueTask InvokeAsync(IRequestContext context)
context.Result = QueryResultBuilder.CreateError(_errorHandler.Handle(error));
}
}

public static RequestCoreMiddleware Create()
=> (core, next) =>
{
var errorHandler = core.SchemaServices.GetRequiredService<IErrorHandler>();
var middleware = new ExceptionMiddleware(next, errorHandler);
var middleware = Create(next, errorHandler);
return context => middleware.InvokeAsync(context);
};
}

internal static ExceptionMiddleware Create(
RequestDelegate next,
IErrorHandler errorHandler)
=> new(next, errorHandler);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

namespace HotChocolate.Execution.Pipeline;

internal sealed class InstrumentationMiddleware(
RequestDelegate next,
[SchemaService] IExecutionDiagnosticEvents diagnosticEvents)
internal sealed class InstrumentationMiddleware
{
private readonly RequestDelegate _next = next ??
throw new ArgumentNullException(nameof(next));
private readonly IExecutionDiagnosticEvents _diagnosticEvents = diagnosticEvents ??
throw new ArgumentNullException(nameof(diagnosticEvents));
private readonly RequestDelegate _next;
private readonly IExecutionDiagnosticEvents _diagnosticEvents;

private InstrumentationMiddleware(RequestDelegate next,
[SchemaService] IExecutionDiagnosticEvents diagnosticEvents)
{
_next = next ??
throw new ArgumentNullException(nameof(next));
_diagnosticEvents = diagnosticEvents ??
throw new ArgumentNullException(nameof(diagnosticEvents));
}

public async ValueTask InvokeAsync(IRequestContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal sealed class OnlyPersistedQueriesAllowedMiddleware
private readonly GraphQLException _exception;
private readonly Dictionary<string, object?> _statusCode = new() { { WellKnownContextData.HttpStatusCode, 400 }, };

public OnlyPersistedQueriesAllowedMiddleware(
private OnlyPersistedQueriesAllowedMiddleware(
RequestDelegate next,
[SchemaService] IExecutionDiagnosticEvents diagnosticEvents,
[SchemaService] IPersistedQueryOptionsAccessor options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@

namespace HotChocolate.Execution.Pipeline;

internal sealed class OperationCacheMiddleware(
RequestDelegate next,
[SchemaService] IExecutionDiagnosticEvents diagnosticEvents,
IPreparedOperationCache operationCache)
internal sealed class OperationCacheMiddleware
{
private readonly RequestDelegate _next = next ??
throw new ArgumentNullException(nameof(next));
private readonly IExecutionDiagnosticEvents _diagnosticEvents = diagnosticEvents ??
throw new ArgumentNullException(nameof(diagnosticEvents));
private readonly IPreparedOperationCache _operationCache = operationCache ??
throw new ArgumentNullException(nameof(operationCache));
private readonly RequestDelegate _next;
private readonly IExecutionDiagnosticEvents _diagnosticEvents;
private readonly IPreparedOperationCache _operationCache;

private OperationCacheMiddleware(RequestDelegate next,
[SchemaService] IExecutionDiagnosticEvents diagnosticEvents,
IPreparedOperationCache operationCache)
{
_next = next ??
throw new ArgumentNullException(nameof(next));
_diagnosticEvents = diagnosticEvents ??
throw new ArgumentNullException(nameof(diagnosticEvents));
_operationCache = operationCache ??
throw new ArgumentNullException(nameof(operationCache));
}

public async ValueTask InvokeAsync(IRequestContext context)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal sealed class OperationComplexityMiddleware
private readonly ComplexityAnalyzerCompiler _compiler;
private readonly VariableCoercionHelper _coercionHelper;

public OperationComplexityMiddleware(
private OperationComplexityMiddleware(
RequestDelegate next,
DocumentValidatorContextPool contextPool,
[SchemaService] IComplexityAnalyzerOptionsAccessor options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,33 @@

namespace HotChocolate.Execution.Pipeline;

internal sealed class OperationExecutionMiddleware(
RequestDelegate next,
IFactory<OperationContextOwner> contextFactory,
[SchemaService] QueryExecutor queryExecutor,
[SchemaService] SubscriptionExecutor subscriptionExecutor,
[SchemaService] ITransactionScopeHandler transactionScopeHandler)
internal sealed class OperationExecutionMiddleware
{
private readonly RequestDelegate _next = next ??
throw new ArgumentNullException(nameof(next));

private readonly IFactory<OperationContextOwner> _contextFactory = contextFactory ??
throw new ArgumentNullException(nameof(contextFactory));

private readonly QueryExecutor _queryExecutor = queryExecutor ??
throw new ArgumentNullException(nameof(queryExecutor));

private readonly SubscriptionExecutor _subscriptionExecutor = subscriptionExecutor ??
throw new ArgumentNullException(nameof(subscriptionExecutor));

private readonly ITransactionScopeHandler _transactionScopeHandler = transactionScopeHandler ??
throw new ArgumentNullException(nameof(transactionScopeHandler));

private readonly RequestDelegate _next;
private readonly IFactory<OperationContextOwner> _contextFactory;
private readonly QueryExecutor _queryExecutor;
private readonly SubscriptionExecutor _subscriptionExecutor;
private readonly ITransactionScopeHandler _transactionScopeHandler;
private object? _cachedQuery;
private object? _cachedMutation;

private OperationExecutionMiddleware(RequestDelegate next,
IFactory<OperationContextOwner> contextFactory,
[SchemaService] QueryExecutor queryExecutor,
[SchemaService] SubscriptionExecutor subscriptionExecutor,
[SchemaService] ITransactionScopeHandler transactionScopeHandler)
{
_next = next ??
throw new ArgumentNullException(nameof(next));
_contextFactory = contextFactory ??
throw new ArgumentNullException(nameof(contextFactory));
_queryExecutor = queryExecutor ??
throw new ArgumentNullException(nameof(queryExecutor));
_subscriptionExecutor = subscriptionExecutor ??
throw new ArgumentNullException(nameof(subscriptionExecutor));
_transactionScopeHandler = transactionScopeHandler ??
throw new ArgumentNullException(nameof(transactionScopeHandler));
}

public async ValueTask InvokeAsync(
IRequestContext context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal sealed class OperationResolverMiddleware
private readonly VariableCoercionHelper _coercionHelper;
private readonly IReadOnlyList<IOperationCompilerOptimizer>? _optimizers;

public OperationResolverMiddleware(
private OperationResolverMiddleware(
RequestDelegate next,
ObjectPool<OperationCompiler> operationCompilerPool,
IEnumerable<IOperationCompilerOptimizer> optimizers,
Expand Down
Loading

0 comments on commit 162598b

Please sign in to comment.