Skip to content

Commit 75975d6

Browse files
authored
Add: Mutable composite JSON document (#8668)
1 parent e8b9b3f commit 75975d6

File tree

178 files changed

+12949
-3638
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+12949
-3638
lines changed

src/All.slnx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
<Project Path="HotChocolate/AspNetCore/src/Transport.Sockets.Client/HotChocolate.Transport.Sockets.Client.csproj" />
4848
<Project Path="HotChocolate/AspNetCore/src/Transport.Sockets/HotChocolate.Transport.Sockets.csproj" />
4949
</Folder>
50-
<Folder Name="/HotChocolate/AspNetCore/src/AspNetCore/" />
5150
<Folder Name="/HotChocolate/AspNetCore/test/">
5251
<Project Path="HotChocolate/AspNetCore/test/AspNetCore.Authorization.Opa.Tests/HotChocolate.AspNetCore.Authorization.Opa.Tests.csproj" />
5352
<Project Path="HotChocolate/AspNetCore/test/AspNetCore.Authorization.Tests/HotChocolate.AspNetCore.Authorization.Tests.csproj" />
@@ -175,6 +174,9 @@
175174
<Project Path="HotChocolate/Diagnostics/test/Diagnostics.Tests/HotChocolate.Diagnostics.Tests.csproj" />
176175
</Folder>
177176
<Folder Name="/HotChocolate/Fusion-vnext/" />
177+
<Folder Name="/HotChocolate/Fusion-vnext/benchmarks/">
178+
<Project Path="HotChocolate/Fusion-vnext/benchmarks/Fusion.Execution.Benchmarks/Fusion.Execution.Benchmarks.csproj" />
179+
</Folder>
178180
<Folder Name="/HotChocolate/Fusion-vnext/src/">
179181
<Project Path="HotChocolate/Fusion-vnext/src/Fusion.Aspire/HotChocolate.Fusion.Aspire.csproj" />
180182
<Project Path="HotChocolate/Fusion-vnext/src/Fusion.AspNetCore/HotChocolate.Fusion.AspNetCore.csproj" />
@@ -188,13 +190,22 @@
188190
<Folder Name="/HotChocolate/Fusion-vnext/test/">
189191
<Project Path="HotChocolate/Fusion-vnext/test/Fusion.AspNetCore.Tests/HotChocolate.Fusion.AspNetCore.Tests.csproj" />
190192
<Project Path="HotChocolate/Fusion-vnext/test/Fusion.Composition.Tests/HotChocolate.Fusion.Composition.Tests.csproj" />
191-
<Project Path="HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/HotChocolate.Fusion.Execution.Tests.csproj" />
192193
<Project Path="HotChocolate/Fusion-vnext/test/Fusion.EventSources.Tests/HotChocolate.Fusion.EventSources.Tests.csproj" />
194+
<Project Path="HotChocolate/Fusion-vnext/test/Fusion.Execution.Tests/HotChocolate.Fusion.Execution.Tests.csproj" />
193195
<Project Path="HotChocolate/Fusion-vnext/test/Fusion.Language.Tests/HotChocolate.Fusion.Language.Tests.csproj" />
194196
<Project Path="HotChocolate/Fusion-vnext/test/Fusion.Packaging.Tests/HotChocolate.Fusion.Packaging.Tests.csproj" />
195197
<Project Path="HotChocolate/Fusion-vnext/test/Fusion.Utilities.Tests/HotChocolate.Fusion.Utilities.Tests.csproj" />
196198
<Project Path="HotChocolate/Fusion-vnext/test/Fusion.Tests.Shared/HotChocolate.Fusion.Tests.Shared.csproj" />
197199
</Folder>
200+
<Folder Name="/HotChocolate/Json/" />
201+
<Folder Name="/HotChocolate/Json/src/" />
202+
<Folder Name="/HotChocolate/Json/src/Json/">
203+
<Project Path="HotChocolate/Json/src/Json/HotChocolate.Text.Json.csproj" />
204+
</Folder>
205+
<Folder Name="/HotChocolate/Json/test/" />
206+
<Folder Name="/HotChocolate/Json/test/Json.Tests/">
207+
<Project Path="HotChocolate/Json/test/Json.Tests/HotChocolate.Text.Json.Tests.csproj" />
208+
</Folder>
198209
<Folder Name="/HotChocolate/Language/" />
199210
<Folder Name="/HotChocolate/Language/src/">
200211
<Project Path="HotChocolate/Language/src/Language.SyntaxTree/HotChocolate.Language.SyntaxTree.csproj" />
@@ -288,12 +299,12 @@
288299
</Folder>
289300
<Folder Name="/HotChocolate/Utilities/" />
290301
<Folder Name="/HotChocolate/Utilities/src/">
302+
<Project Path="HotChocolate/Utilities/src/Utilities.Base36/HotChocolate.Utilities.Base36.csproj" />
291303
<Project Path="HotChocolate/Utilities/src/Utilities.Buffers/HotChocolate.Utilities.Buffers.csproj" />
292304
<Project Path="HotChocolate/Utilities/src/Utilities.DependencyInjection/HotChocolate.Utilities.DependencyInjection.csproj" />
293305
<Project Path="HotChocolate/Utilities/src/Utilities.Introspection/HotChocolate.Utilities.Introspection.csproj" />
294306
<Project Path="HotChocolate/Utilities/src/Utilities.Tasks/HotChocolate.Utilities.Tasks.csproj" />
295307
<Project Path="HotChocolate/Utilities/src/Utilities/HotChocolate.Utilities.csproj" />
296-
<Project Path="HotChocolate/Utilities/src/Utilities.Base36/HotChocolate.Utilities.Base36.csproj" />
297308
</Folder>
298309
<Folder Name="/HotChocolate/Utilities/test/">
299310
<Project Path="HotChocolate/Utilities/test/Utilities.Introspection.Tests/HotChocolate.Utilities.Introspection.Tests.csproj" />
@@ -353,4 +364,4 @@
353364
<Folder Name="/StrawberryShake/Tooling/test/">
354365
<Project Path="StrawberryShake/Tooling/test/Configuration.Tests/StrawberryShake.Tools.Configuration.Tests.csproj" />
355366
</Folder>
356-
</Solution>
367+
</Solution>

src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Extensions/HttpContextExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public static bool IncludeOperationPlan(this HttpContext context)
2626
return false;
2727
}
2828

29-
// TODO : Implement this
3029
public static string? TryGetCostSwitch(this HttpContext context)
3130
{
3231
var headers = context.Request.Headers;

src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/Formatters/DefaultHttpResponseFormatter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private async ValueTask FormatInternalAsync(
224224

225225
OnWriteResponseHeaders(operationResult, format, response.Headers);
226226

227-
await format.Formatter.FormatAsync(result, response.Body, cancellationToken);
227+
await format.Formatter.FormatAsync(result, response.BodyWriter, cancellationToken);
228228
break;
229229
}
230230

@@ -238,7 +238,7 @@ private async ValueTask FormatInternalAsync(
238238
OnWriteResponseHeaders(resultBatch, format, response.Headers);
239239
await response.Body.FlushAsync(cancellationToken);
240240

241-
await format.Formatter.FormatAsync(result, response.Body, cancellationToken);
241+
await format.Formatter.FormatAsync(result, response.BodyWriter, cancellationToken);
242242
break;
243243
}
244244

@@ -252,7 +252,7 @@ private async ValueTask FormatInternalAsync(
252252
OnWriteResponseHeaders(responseStream, format, response.Headers);
253253
await response.Body.FlushAsync(cancellationToken);
254254

255-
await format.Formatter.FormatAsync(result, response.Body, cancellationToken);
255+
await format.Formatter.FormatAsync(result, response.BodyWriter, cancellationToken);
256256
break;
257257
}
258258

src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/HttpMultipartMiddleware.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ protected override async ValueTask<IReadOnlyList<GraphQLRequest>> ParseRequestsF
8080

8181
// Parse the string values of interest from the IFormCollection
8282
var multipartRequest = ParseMultipartRequest(form);
83-
var requests = session.RequestParser.ParseRequest(
84-
multipartRequest.Operations);
83+
var requests = session.RequestParser.ParseRequest(multipartRequest.Operations);
8584

8685
foreach (var graphQLRequest in requests)
8786
{

src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/HttpPostMiddlewareBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ protected async Task HandleRequestAsync(HttpContext context, ExecutorSession ses
221221
// to the HTTP response stream.
222222
Debug.Assert(result is not null, "No GraphQL result was created.");
223223

224-
if (result is IOperationResult queryResult)
224+
if (result is IOperationResult operationResult)
225225
{
226-
formatScope = session.DiagnosticEvents.FormatHttpResponse(context, queryResult);
226+
formatScope = session.DiagnosticEvents.FormatHttpResponse(context, operationResult);
227227
}
228228

229229
await session.WriteResultAsync(context, result, acceptMediaTypes, statusCode);

src/HotChocolate/AspNetCore/src/Transport.Abstractions/HotChocolate.Transport.Abstractions.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<InternalsVisibleTo Include="HotChocolate.Transport.Http" />
1616
<InternalsVisibleTo Include="HotChocolate.Transport.Sockets" />
1717
<InternalsVisibleTo Include="HotChocolate.Transport.Sockets.Client" />
18+
<InternalsVisibleTo Include="HotChocolate.Fusion.Execution" />
1819
</ItemGroup>
1920

2021
<ItemGroup>

src/HotChocolate/AspNetCore/src/Transport.Formatters/EventStreamResultFormatter.cs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,31 @@ public sealed class EventStreamResultFormatter(JsonResultFormatterOptions option
2424
/// <summary>
2525
/// Formats an <see cref="IExecutionResult"/> into an SSE stream.
2626
/// </summary>
27-
/// <param name="result"></param>
28-
/// <param name="outputStream"></param>
29-
/// <param name="cancellationToken"></param>
30-
/// <returns></returns>
31-
/// <exception cref="ArgumentNullException"></exception>
32-
/// <exception cref="NotSupportedException"></exception>
3327
public ValueTask FormatAsync(
3428
IExecutionResult result,
35-
Stream outputStream,
29+
PipeWriter writer,
3630
CancellationToken cancellationToken = default)
3731
{
3832
ArgumentNullException.ThrowIfNull(result);
39-
ArgumentNullException.ThrowIfNull(outputStream);
33+
ArgumentNullException.ThrowIfNull(writer);
4034

4135
return result switch
4236
{
4337
IOperationResult operationResult
44-
=> FormatOperationResultAsync(operationResult, outputStream, cancellationToken),
38+
=> FormatOperationResultAsync(operationResult, writer, cancellationToken),
4539
OperationResultBatch resultBatch
46-
=> FormatResultBatchAsync(resultBatch, outputStream, cancellationToken),
40+
=> FormatResultBatchAsync(resultBatch, writer, cancellationToken),
4741
IResponseStream responseStream
48-
=> FormatResponseStreamAsync(responseStream, outputStream, cancellationToken),
42+
=> FormatResponseStreamAsync(responseStream, writer, cancellationToken),
4943
_ => throw new NotSupportedException()
5044
};
5145
}
5246

5347
private async ValueTask FormatOperationResultAsync(
5448
IOperationResult operationResult,
55-
Stream outputStream,
49+
PipeWriter writer,
5650
CancellationToken ct)
5751
{
58-
Exception? exception = null;
59-
var writer = outputStream.CreatePipeWriter();
6052
var scope = Log.FormatOperationResultStart();
6153

6254
try
@@ -67,24 +59,21 @@ private async ValueTask FormatOperationResultAsync(
6759
catch (Exception ex)
6860
{
6961
scope?.AddError(ex);
70-
exception = ex;
7162
throw;
7263
}
7364
finally
7465
{
7566
scope?.Dispose();
76-
await writer.CompleteAsync(exception).ConfigureAwait(false);
7767
}
7868
}
7969

8070
private async ValueTask FormatResultBatchAsync(
8171
OperationResultBatch resultBatch,
82-
Stream outputStream,
72+
PipeWriter writer,
8373
CancellationToken ct)
8474
{
8575
Exception? exception = null;
8676
using var semaphore = new SemaphoreSlim(1, 1);
87-
var writer = outputStream.CreatePipeWriter();
8877
List<Task>? streams = null;
8978
KeepAliveJob? keepAlive = null;
9079

@@ -157,8 +146,6 @@ private async ValueTask FormatResultBatchAsync(
157146
{
158147
await TryWriteCompleteAsync(writer, ct).ConfigureAwait(false);
159148
}
160-
161-
await writer.CompleteAsync(exception).ConfigureAwait(false);
162149
}
163150

164151
// we rethrow any stream exception that happened.
@@ -170,12 +157,11 @@ private async ValueTask FormatResultBatchAsync(
170157

171158
private async ValueTask FormatResponseStreamAsync(
172159
IResponseStream responseStream,
173-
Stream outputStream,
160+
PipeWriter writer,
174161
CancellationToken ct)
175162
{
176163
Exception? exception = null;
177164
using var semaphore = new SemaphoreSlim(1, 1);
178-
var writer = outputStream.CreatePipeWriter();
179165

180166
try
181167
{
@@ -205,8 +191,6 @@ private async ValueTask FormatResponseStreamAsync(
205191
{
206192
await TryWriteCompleteAsync(writer, ct).ConfigureAwait(false);
207193
}
208-
209-
await writer.CompleteAsync(exception).ConfigureAwait(false);
210194
}
211195
}
212196

src/HotChocolate/AspNetCore/src/Transport.Formatters/JsonLinesResultFormatter.cs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@ public sealed class JsonLinesResultFormatter(JsonResultFormatterOptions options)
1010
{
1111
private readonly JsonResultFormatter _payloadFormatter = new(options with { Indented = false });
1212

13+
/// <summary>
14+
/// Formats an <see cref="IExecutionResult"/> into an JSONL stream.
15+
/// </summary>
1316
public ValueTask FormatAsync(
1417
IExecutionResult result,
15-
Stream outputStream,
18+
PipeWriter writer,
1619
CancellationToken cancellationToken = default)
1720
{
1821
ArgumentNullException.ThrowIfNull(result);
19-
ArgumentNullException.ThrowIfNull(outputStream);
22+
ArgumentNullException.ThrowIfNull(writer);
2023

2124
return result switch
2225
{
2326
IOperationResult operationResult
24-
=> FormatOperationResultAsync(operationResult, outputStream, cancellationToken),
27+
=> FormatOperationResultAsync(operationResult, writer, cancellationToken),
2528
OperationResultBatch resultBatch
26-
=> FormatResultBatchAsync(resultBatch, outputStream, cancellationToken),
29+
=> FormatResultBatchAsync(resultBatch, writer, cancellationToken),
2730
IResponseStream responseStream
28-
=> FormatResponseStreamAsync(responseStream, outputStream, cancellationToken),
31+
=> FormatResponseStreamAsync(responseStream, writer, cancellationToken),
2932
_ => throw new NotSupportedException()
3033
};
3134
}
@@ -35,11 +38,9 @@ IResponseStream responseStream
3538
/// </summary>
3639
private async ValueTask FormatOperationResultAsync(
3740
IOperationResult operationResult,
38-
Stream outputStream,
41+
PipeWriter writer,
3942
CancellationToken ct)
4043
{
41-
Exception? exception = null;
42-
var writer = outputStream.CreatePipeWriter();
4344
var scope = Log.FormatOperationResultStart();
4445

4546
try
@@ -50,13 +51,11 @@ private async ValueTask FormatOperationResultAsync(
5051
catch (Exception ex)
5152
{
5253
scope?.AddError(ex);
53-
exception = ex;
5454
throw;
5555
}
5656
finally
5757
{
5858
scope?.Dispose();
59-
await writer.CompleteAsync(exception).ConfigureAwait(false);
6059
}
6160
}
6261

@@ -65,12 +64,11 @@ private async ValueTask FormatOperationResultAsync(
6564
/// </summary>
6665
private async ValueTask FormatResultBatchAsync(
6766
OperationResultBatch resultBatch,
68-
Stream outputStream,
67+
PipeWriter writer,
6968
CancellationToken ct)
7069
{
7170
Exception? exception = null;
7271
using var semaphore = new SemaphoreSlim(1, 1);
73-
var writer = outputStream.CreatePipeWriter();
7472
List<Task>? streams = null;
7573
KeepAliveJob? keepAlive = null;
7674

@@ -138,7 +136,6 @@ private async ValueTask FormatResultBatchAsync(
138136
var streamError = await TryCompleteStreamsAsync(streams).ConfigureAwait(false);
139137
exception ??= streamError;
140138
keepAlive?.Dispose();
141-
await writer.CompleteAsync(exception).ConfigureAwait(false);
142139
}
143140

144141
// we rethrow any stream exception that happened.
@@ -150,12 +147,10 @@ private async ValueTask FormatResultBatchAsync(
150147

151148
private async ValueTask FormatResponseStreamAsync(
152149
IResponseStream responseStream,
153-
Stream outputStream,
150+
PipeWriter writer,
154151
CancellationToken ct)
155152
{
156-
Exception? exception = null;
157153
using var semaphore = new SemaphoreSlim(1, 1);
158-
var writer = outputStream.CreatePipeWriter();
159154

160155
try
161156
{
@@ -167,20 +162,10 @@ private async ValueTask FormatResponseStreamAsync(
167162

168163
await writer.FlushAsync(ct).ConfigureAwait(false);
169164
}
170-
catch (OperationCanceledException ex)
165+
catch (OperationCanceledException)
171166
{
172167
// if the operation was canceled, we do not need to log this
173168
// and will stop gracefully.
174-
exception = ex;
175-
}
176-
catch (Exception ex)
177-
{
178-
exception = ex;
179-
throw;
180-
}
181-
finally
182-
{
183-
await writer.CompleteAsync(exception).ConfigureAwait(false);
184169
}
185170
}
186171

0 commit comments

Comments
 (0)