-
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed parsing issue in Utf8GraphQLRequestParser#ParseStringOrNull (#7703
- Loading branch information
1 parent
8e94289
commit 6824099
Showing
13 changed files
with
600 additions
and
2 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
8 changes: 8 additions & 0 deletions
8
src/HotChocolate/Core/src/Abstractions/Execution/WarmupExecutionResult.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,8 @@ | ||
namespace HotChocolate.Execution; | ||
|
||
public sealed class WarmupExecutionResult : ExecutionResult | ||
{ | ||
public override ExecutionResultKind Kind => ExecutionResultKind.WarmupResult; | ||
|
||
public override IReadOnlyDictionary<string, object?>? ContextData => null; | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/HotChocolate/Core/src/Execution/Extensions/WarmupRequestContextExtensions.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,7 @@ | ||
namespace HotChocolate.Execution; | ||
|
||
public static class WarmupRequestExecutorExtensions | ||
{ | ||
public static bool IsWarmupRequest(this IRequestContext requestContext) | ||
=> requestContext.ContextData.ContainsKey(WellKnownContextData.IsWarmupRequest); | ||
} |
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
22 changes: 22 additions & 0 deletions
22
src/HotChocolate/Core/src/Execution/Pipeline/SkipWarmupExecutionMiddleware.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,22 @@ | ||
namespace HotChocolate.Execution.Pipeline; | ||
|
||
internal sealed class SkipWarmupExecutionMiddleware(RequestDelegate next) | ||
{ | ||
public async ValueTask InvokeAsync(IRequestContext context) | ||
{ | ||
if (context.IsWarmupRequest()) | ||
{ | ||
context.Result = new WarmupExecutionResult(); | ||
return; | ||
} | ||
|
||
await next(context).ConfigureAwait(false); | ||
} | ||
|
||
public static RequestCoreMiddleware Create() | ||
=> (_, next) => | ||
{ | ||
var middleware = new SkipWarmupExecutionMiddleware(next); | ||
return context => middleware.InvokeAsync(context); | ||
}; | ||
} |
100 changes: 100 additions & 0 deletions
100
src/HotChocolate/Core/test/Execution.Tests/WarmupRequestTests.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,100 @@ | ||
using HotChocolate.Execution.Caching; | ||
using HotChocolate.Language; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
|
||
namespace HotChocolate.Execution; | ||
|
||
public class WarmupRequestTests | ||
{ | ||
[Fact] | ||
public async Task Warmup_Request_Warms_Up_Caches() | ||
{ | ||
// arrange | ||
var executor = await new ServiceCollection() | ||
.AddGraphQL() | ||
.AddQueryType<Query>() | ||
.BuildRequestExecutorAsync(); | ||
|
||
var documentId = "f614e9a2ed367399e87751d41ca09105"; | ||
var warmupRequest = OperationRequestBuilder.New() | ||
.SetDocument("query test($name: String!) { greeting(name: $name) }") | ||
.SetDocumentId(documentId) | ||
.MarkAsWarmupRequest() | ||
.Build(); | ||
|
||
var regularRequest = OperationRequestBuilder.New() | ||
.SetDocumentId(documentId) | ||
.SetVariableValues(new Dictionary<string, object?> { ["name"] = "Foo" }) | ||
.Build(); | ||
|
||
// act 1 | ||
var warmupResult = await executor.ExecuteAsync(warmupRequest); | ||
|
||
// assert 1 | ||
Assert.IsType<WarmupExecutionResult>(warmupResult); | ||
|
||
var provider = executor.Services.GetCombinedServices(); | ||
var documentCache = provider.GetRequiredService<IDocumentCache>(); | ||
var operationCache = provider.GetRequiredService<IPreparedOperationCache>(); | ||
|
||
Assert.True(documentCache.TryGetDocument(documentId, out _)); | ||
Assert.Equal(1, operationCache.Count); | ||
|
||
// act 2 | ||
var regularResult = await executor.ExecuteAsync(regularRequest); | ||
var regularOperationResult = regularResult.ExpectOperationResult(); | ||
|
||
// assert 2 | ||
Assert.Null(regularOperationResult.Errors); | ||
Assert.NotNull(regularOperationResult.Data); | ||
Assert.NotEmpty(regularOperationResult.Data); | ||
|
||
Assert.True(documentCache.TryGetDocument(documentId, out _)); | ||
Assert.Equal(1, operationCache.Count); | ||
} | ||
|
||
[Fact] | ||
public async Task Warmup_Request_Can_Skip_Persisted_Operation_Check() | ||
{ | ||
// arrange | ||
var executor = await new ServiceCollection() | ||
.AddGraphQL() | ||
.ConfigureSchemaServices(services => | ||
{ | ||
services.AddSingleton<IOperationDocumentStorage>(_ => new Mock<IOperationDocumentStorage>().Object); | ||
}) | ||
.AddQueryType<Query>() | ||
.ModifyRequestOptions(options => | ||
{ | ||
options.PersistedOperations.OnlyAllowPersistedDocuments = true; | ||
}) | ||
.UsePersistedOperationPipeline() | ||
.BuildRequestExecutorAsync(); | ||
|
||
var documentId = "f614e9a2ed367399e87751d41ca09105"; | ||
var warmupRequest = OperationRequestBuilder.New() | ||
.SetDocument("query test($name: String!) { greeting(name: $name) }") | ||
.SetDocumentId(documentId) | ||
.MarkAsWarmupRequest() | ||
.Build(); | ||
|
||
// act | ||
var warmupResult = await executor.ExecuteAsync(warmupRequest); | ||
|
||
// assert | ||
Assert.IsType<WarmupExecutionResult>(warmupResult); | ||
|
||
var provider = executor.Services.GetCombinedServices(); | ||
var documentCache = provider.GetRequiredService<IDocumentCache>(); | ||
var operationCache = provider.GetRequiredService<IPreparedOperationCache>(); | ||
|
||
Assert.True(documentCache.TryGetDocument(documentId, out _)); | ||
Assert.Equal(1, operationCache.Count); | ||
} | ||
|
||
public class Query | ||
{ | ||
public string Greeting(string name) => $"Hello {name}"; | ||
} | ||
} |
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
Oops, something went wrong.