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 162598b commit ae7a44a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 18 deletions.
17 changes: 12 additions & 5 deletions src/HotChocolate/Caching/src/Caching/QueryCacheMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@

namespace HotChocolate.Caching;

internal sealed class QueryCacheMiddleware(
RequestDelegate next,
[SchemaService] ICacheControlOptionsAccessor optionsAccessor)
internal sealed class QueryCacheMiddleware
{
private readonly ICacheControlOptions _options = optionsAccessor.CacheControl;
private readonly ICacheControlOptions _options;
private readonly RequestDelegate _next;

private QueryCacheMiddleware(
RequestDelegate next,
[SchemaService] ICacheControlOptionsAccessor optionsAccessor)
{
_next = next;
_options = optionsAccessor.CacheControl;
}

public async ValueTask InvokeAsync(IRequestContext context)
{
await next(context).ConfigureAwait(false);
await _next(context).ConfigureAwait(false);

if (!_options.Enable || context.ContextData.ContainsKey(SkipQueryCaching))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using CookieCrumble;
using HotChocolate.Types;
using Microsoft.Extensions.DependencyInjection;
using Snapshooter.Xunit;
using Xunit;

namespace HotChocolate.Caching.Http.Tests;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Headers": [],
"ContentHeaders": [
{
Expand All @@ -9,4 +9,4 @@
}
],
"Body": "{\"data\":{\"field\":\"\"}}"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Headers": [
{
"Key": "Cache-Control",
Expand All @@ -16,4 +16,4 @@
}
],
"Body": "{}"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Headers": [
{
"Key": "Cache-Control",
Expand All @@ -16,4 +16,4 @@
}
],
"Body": "{}"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"Headers": [
{
"Key": "Cache-Control",
Expand All @@ -16,4 +16,4 @@
}
],
"Body": "{}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,19 @@ private bool CoerceVariable(
var variables = CoerceVariables(context, _coercionHelper, operationDefinition.VariableDefinitions);
return variables.GetVariable<bool>(variable.Name.Value);
}

public static RequestCoreMiddleware Create()
=> (core, next) =>
{
var operationCompilerPool = core.Services.GetRequiredService<ObjectPool<OperationCompiler>>();
var optimizers = core.Services.GetRequiredService<IEnumerable<IOperationCompilerOptimizer>>();
var optimizers1 = core.Services.GetRequiredService<IEnumerable<IOperationCompilerOptimizer>>();
var optimizers2 = core.SchemaServices.GetRequiredService<IEnumerable<IOperationCompilerOptimizer>>();
var coercionHelper = core.Services.GetRequiredService<VariableCoercionHelper>();
var middleware = new OperationResolverMiddleware(next, operationCompilerPool, optimizers, coercionHelper);
var middleware = new OperationResolverMiddleware(
next,
operationCompilerPool,
optimizers1.Concat(optimizers2),
coercionHelper);
return context => middleware.InvokeAsync(context);
};
}
}

0 comments on commit ae7a44a

Please sign in to comment.