Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions src/All.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@
<Project Path="HotChocolate/Core/src/Execution.Operation.Abstractions/HotChocolate.Execution.Operation.Abstractions.csproj" />
<Project Path="HotChocolate/Core/src/Execution.Pipeline/HotChocolate.Execution.Pipeline.csproj" />
<Project Path="HotChocolate/Core/src/Execution.Projections/HotChocolate.Execution.Projections.csproj" />
<Project Path="HotChocolate/Core/src/Execution/HotChocolate.Execution.csproj" />
<Project Path="HotChocolate/Core/src/Features/HotChocolate.Features.csproj" />
<Project Path="HotChocolate/Core/src/Fetching/HotChocolate.Fetching.csproj" />
<Project Path="HotChocolate/Core/src/Subscriptions.InMemory/HotChocolate.Subscriptions.InMemory.csproj" />
<Project Path="HotChocolate/Core/src/Subscriptions.Nats/HotChocolate.Subscriptions.Nats.csproj" />
<Project Path="HotChocolate/Core/src/Subscriptions.Postgres/HotChocolate.Subscriptions.Postgres.csproj" />
Expand All @@ -112,7 +110,6 @@
<Project Path="HotChocolate/Core/src/Types.Queries/HotChocolate.Types.Queries.csproj" />
<Project Path="HotChocolate/Core/src/Types.Scalars.Upload/HotChocolate.Types.Scalars.Upload.csproj" />
<Project Path="HotChocolate/Core/src/Types.Scalars/HotChocolate.Types.Scalars.csproj" />
<Project Path="HotChocolate/Core/src/Types.Shared/HotChocolate.Types.Shared.csproj" />
<Project Path="HotChocolate/Core/src/Types.Validation/HotChocolate.Types.Validation.csproj" />
<Project Path="HotChocolate/Core/src/Types/HotChocolate.Types.csproj" />
<Project Path="HotChocolate/Core/src/Validation/HotChocolate.Validation.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<ProjectReference Include="..\CookieCrumble\CookieCrumble.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\AspNetCore\src\Transport.Abstractions\HotChocolate.Transport.Abstractions.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\AspNetCore\src\Transport.Http\HotChocolate.Transport.Http.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\Core\src\Execution\HotChocolate.Execution.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\Core\src\Types\HotChocolate.Types.csproj" />
<ProjectReference Include="..\..\..\HotChocolate\Language\src\Language.SyntaxTree\HotChocolate.Language.SyntaxTree.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Core\src\Execution\HotChocolate.Execution.csproj" />
<ProjectReference Include="..\..\..\Core\src\Types\HotChocolate.Types.csproj" />
<ProjectReference Include="..\Adapters.Mcp.Core\HotChocolate.Adapters.Mcp.Core.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

using HotChocolate.Buffers;
#if FUSION
using System.Buffers;
using System.Net;
Expand Down Expand Up @@ -160,7 +162,7 @@ private async ValueTask<OperationResult> ReadAsResultInternalAsync(string? charS
#if FUSION
// we try and read the first chunk into a single chunk.
var reader = PipeReader.Create(stream, s_options);
var currentChunk = JsonMemory.Rent();
var currentChunk = JsonMemory.Rent(JsonMemoryKind.Json);
var currentChunkPosition = 0;
var chunkIndex = 0;
var chunks = ArrayPool<byte[]>.Shared.Rent(64);
Expand Down Expand Up @@ -215,7 +217,7 @@ private async ValueTask<OperationResult> ReadAsResultInternalAsync(string? charS
}

chunks[chunkIndex++] = currentChunk;
currentChunk = JsonMemory.Rent();
currentChunk = JsonMemory.Rent(JsonMemoryKind.Json);
currentChunkPosition = 0;
}
}
Expand Down Expand Up @@ -253,7 +255,7 @@ private async ValueTask<OperationResult> ReadAsResultInternalAsync(string? charS
}

chunks[chunkIndex++] = currentChunk;
currentChunk = JsonMemory.Rent();
currentChunk = JsonMemory.Rent(JsonMemoryKind.Json);
currentChunkPosition = 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Buffers;
using System.IO.Pipelines;
using System.Runtime.CompilerServices;
using HotChocolate.Buffers;
using HotChocolate.Fusion.Text.Json;
#else
using System.Buffers;
Expand Down Expand Up @@ -103,7 +104,7 @@ private static SourceResultDocument ParseDocument(ReadOnlySequence<byte> lineBuf

// Ceiling division to make sure we end up with the right amount of chunks.
var chunksNeeded = (requiredSize + JsonMemory.BufferSize - 1) / JsonMemory.BufferSize;
var chunks = JsonMemory.RentRange(chunksNeeded);
var chunks = JsonMemory.RentRange(JsonMemoryKind.Json, chunksNeeded);
var chunkIndex = 0;
var chunkPosition = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Buffers;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using HotChocolate.Fusion.Text.Json;
using HotChocolate.Buffers;

#else
using System.Runtime.CompilerServices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Buffers;
using System.IO.Pipelines;
using System.Runtime.CompilerServices;
using HotChocolate.Buffers;
using HotChocolate.Fusion.Text.Json;
#else
using System.Buffers;
Expand Down Expand Up @@ -107,7 +108,7 @@ public async IAsyncEnumerator<OperationResult> GetAsyncEnumerator(
case SseEventType.Complete:
reader.AdvanceTo(buffer.GetPosition(1, position.Value));
#if FUSION
JsonMemory.Return(eventBuffers);
JsonMemory.Return(JsonMemoryKind.Json, eventBuffers);
eventBuffers.Clear();
#endif
yield break;
Expand Down Expand Up @@ -162,7 +163,7 @@ public async IAsyncEnumerator<OperationResult> GetAsyncEnumerator(
await reader.CompleteAsync().ConfigureAwait(false);
#if FUSION
// we return whatever is in here.
JsonMemory.Return(eventBuffers);
JsonMemory.Return(JsonMemoryKind.Json, eventBuffers);
#endif
}
}
Expand Down Expand Up @@ -232,7 +233,7 @@ private static void WriteBytesToChunks(List<byte[]> chunks, ref int currentPosit
if (chunks.Count == 0 || currentPosition >= JsonMemory.BufferSize)
{
currentPosition = 0;
chunks.Add(JsonMemory.Rent());
chunks.Add(JsonMemory.Rent(JsonMemoryKind.Json));
}

var currentChunk = chunks[^1];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Immutable;
using System.Runtime.CompilerServices;
using HotChocolate.Execution.Processing;
using HotChocolate.Language;
using HotChocolate.Types;
Expand All @@ -15,15 +14,16 @@ internal sealed class CacheControlConstraintsOptimizer : IOperationOptimizer
{
public void OptimizeOperation(OperationOptimizerContext context)
{
if (context.Definition.Operation is not OperationType.Query
|| context.HasIncrementalParts
// TODO : we need to include this again when defer is back.
if (context.Operation.Kind is not OperationType.Query
// || context.HasIncrementalParts
|| ContainsIntrospectionFields(context))
{
// if this is an introspection query, we will not cache it.
return;
}

var constraints = ComputeCacheControlConstraints(context.CreateOperation());
var constraints = ComputeCacheControlConstraints(context.Operation);

if (constraints.MaxAge is not null || constraints.SharedMaxAge is not null)
{
Expand All @@ -38,25 +38,13 @@ public void OptimizeOperation(OperationOptimizerContext context)
: null
};

context.ContextData.Add(
ExecutionContextData.CacheControlConstraints,
constraints);

context.ContextData.Add(
ExecutionContextData.CacheControlHeaderValue,
headerValue);
}

if (constraints.Vary is { Length: > 0 })
{
context.ContextData.Add(
ExecutionContextData.VaryHeaderValue,
string.Join(", ", constraints.Vary));
context.Operation.Features.SetSafe(constraints);
context.Operation.Features.SetSafe(headerValue);
}
}

private static ImmutableCacheConstraints ComputeCacheControlConstraints(
IOperation operation)
Operation operation)
{
var constraints = new CacheControlConstraints();
var rootSelections = operation.RootSelectionSet.Selections;
Expand Down Expand Up @@ -91,9 +79,9 @@ private static ImmutableCacheConstraints ComputeCacheControlConstraints(
}

private static void ProcessSelection(
ISelection selection,
Selection selection,
CacheControlConstraints constraints,
IOperation operation)
Operation operation)
{
var field = selection.Field;
var maxAgeSet = false;
Expand All @@ -117,19 +105,18 @@ private static void ProcessSelection(
}
}

if (selection.SelectionSet is not null)
if (selection.HasSelections)
{
var possibleTypes = operation.GetPossibleTypes(selection);

foreach (var type in possibleTypes)
{
var selectionSet = Unsafe.As<SelectionSet>(operation.GetSelectionSet(selection, type));
var length = selectionSet.Selections.Count;
ref var start = ref selectionSet.GetSelectionsReference();
var selectionSet = operation.GetSelectionSet(selection, type);
var selections = selectionSet.Selections;

for (var i = 0; i < length; i++)
foreach (var childSelection in selections)
{
ProcessSelection(Unsafe.Add(ref start, i), constraints, operation);
ProcessSelection(childSelection, constraints, operation);
}
}
}
Expand Down Expand Up @@ -223,13 +210,11 @@ void ExtractCacheControlDetailsFromDirectives(

private static bool ContainsIntrospectionFields(OperationOptimizerContext context)
{
var length = context.RootSelectionSet.Selections.Count;
ref var start = ref ((SelectionSet)context.RootSelectionSet).GetSelectionsReference();
var selections = context.Operation.RootSelectionSet.Selections;

for (var i = 0; i < length; i++)
foreach (var selection in selections)
{
var field = Unsafe.Add(ref start, i).Field;

var field = selection.Field;
if (field.IsIntrospectionField
&& !field.Name.EqualsOrdinal(IntrospectionFieldNames.TypeName))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Core\src\Execution\HotChocolate.Execution.csproj" />
<ProjectReference Include="..\..\..\Core\src\Types\HotChocolate.Types.csproj" />
</ItemGroup>

Expand Down
12 changes: 12 additions & 0 deletions src/HotChocolate/Caching/src/Caching/ImmutableCacheConstraints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,16 @@ internal sealed class ImmutableCacheConstraints(
public CacheControlScope Scope { get; } = scope;

public ImmutableArray<string> Vary { get; } = vary;

public string VaryString
{
get
{
field ??= Vary.Length is 0
? string.Empty
: string.Join(", ", Vary);

return field;
}
}
}
12 changes: 5 additions & 7 deletions src/HotChocolate/Caching/src/Caching/QueryCacheMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public async ValueTask InvokeAsync(RequestContext context)
}

if (!context.TryGetOperation(out var operation)
|| !operation.ContextData.TryGetValue(ExecutionContextData.CacheControlHeaderValue, out var value)
|| value is not CacheControlHeaderValue cacheControlHeaderValue)
|| !operation.Features.TryGet<CacheControlHeaderValue>(out var headerValue)
|| !operation.Features.TryGet<ImmutableCacheConstraints>(out var constraints))
{
return;
}
Expand All @@ -46,13 +46,11 @@ operationResult.ContextData is not null
? new ExtensionData(operationResult.ContextData)
: [];

contextData.Add(ExecutionContextData.CacheControlHeaderValue, cacheControlHeaderValue);
contextData.Add(ExecutionContextData.CacheControlHeaderValue, headerValue);

if (operation.ContextData.TryGetValue(ExecutionContextData.VaryHeaderValue, out var varyValue)
&& varyValue is string varyHeaderValue
&& !string.IsNullOrEmpty(varyHeaderValue))
if (constraints.Vary.Length > 0)
{
contextData.Add(ExecutionContextData.VaryHeaderValue, varyHeaderValue);
contextData.Add(ExecutionContextData.VaryHeaderValue, constraints.Vary);
}

context.Result = operationResult.WithContextData(contextData);
Expand Down
3 changes: 0 additions & 3 deletions src/HotChocolate/Core/HotChocolate.Core.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
<Project Path="src/Execution.Configuration.Abstractions/HotChocolate.Execution.Configuration.Abstractions.csproj" />
<Project Path="src/Execution.Pipeline/HotChocolate.Execution.Pipeline.csproj" />
<Project Path="src/Execution.Projections/HotChocolate.Execution.Projections.csproj" />
<Project Path="src/Execution/HotChocolate.Execution.csproj" />
<Project Path="src/Features/HotChocolate.Features.csproj" />
<Project Path="src/Fetching/HotChocolate.Fetching.csproj" />
<Project Path="src/Subscriptions.InMemory/HotChocolate.Subscriptions.InMemory.csproj" />
<Project Path="src/Subscriptions.Nats/HotChocolate.Subscriptions.Nats.csproj" />
<Project Path="src/Subscriptions.Postgres/HotChocolate.Subscriptions.Postgres.csproj" />
Expand All @@ -29,7 +27,6 @@
<Project Path="src/Types.Queries/HotChocolate.Types.Queries.csproj" />
<Project Path="src/Types.Scalars.Upload/HotChocolate.Types.Scalars.Upload.csproj" />
<Project Path="src/Types.Scalars/HotChocolate.Types.Scalars.csproj" />
<Project Path="src/Types.Shared/HotChocolate.Types.Shared.csproj" />
<Project Path="src/Types.Validation/HotChocolate.Types.Validation.csproj" />
<Project Path="src/Types/HotChocolate.Types.csproj" />
<Project Path="src/Validation/HotChocolate.Validation.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ private void SetError(
.SetMessage(AuthorizeMiddleware_NoDefaultPolicy)
.SetCode(ErrorCodes.Authentication.NoDefaultPolicy)
.SetPath(context.Path)
.AddLocation(context.Selection.SyntaxNode)
.AddLocations(context.Selection)
.Build(),
AuthorizeResult.PolicyNotFound
=> ErrorBuilder.New()
.SetMessage(
AuthorizeMiddleware_PolicyNotFound,
_directive.Policy!)
_directive.Policy)
.SetCode(ErrorCodes.Authentication.PolicyNotFound)
.SetPath(context.Path)
.AddLocation(context.Selection.SyntaxNode)
.AddLocations(context.Selection)
.Build(),
_
=> ErrorBuilder.New()
Expand All @@ -88,7 +88,7 @@ private void SetError(
? ErrorCodes.Authentication.NotAuthorized
: ErrorCodes.Authentication.NotAuthenticated)
.SetPath(context.Path)
.AddLocation(context.Selection.SyntaxNode)
.AddLocations(context.Selection)
.Build()
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Core\src\Execution\HotChocolate.Execution.csproj" />
<ProjectReference Include="..\..\..\Core\src\Types\HotChocolate.Types.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/HotChocolate/Core/src/Core/HotChocolate.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
<ProjectReference Include="..\Types.CursorPagination\HotChocolate.Types.CursorPagination.csproj" />
<ProjectReference Include="..\Types.CursorPagination.Extensions\HotChocolate.Types.CursorPagination.Extensions.csproj" />
<ProjectReference Include="..\Validation\HotChocolate.Validation.csproj" />
<ProjectReference Include="..\Fetching\HotChocolate.Fetching.csproj" />
<ProjectReference Include="..\Execution\HotChocolate.Execution.csproj" />
</ItemGroup>

</Project>
Loading
Loading