Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Error Behavior in Query Plan #6532

Merged
merged 1 commit into from
Sep 13, 2023
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/HotChocolate/Fusion/src/Core/Execution/Nodes/Resolve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ protected override async Task OnExecuteAsync(
RequestState state,
CancellationToken cancellationToken)
{
if (state.TryGetState(SelectionSet, out var executionState))
if (!state.TryGetState(SelectionSet, out var executionState))
{
return;
}

try
{
var requests = new SubgraphGraphQLRequest[executionState.Count];

Expand All @@ -64,6 +69,11 @@ protected override async Task OnExecuteAsync(
ProcessResponses(context, executionState, requests, responses, SubgraphName);
}
}
catch(Exception ex)
{
var error = context.OperationContext.ErrorHandler.CreateUnexpectedError(ex);
context.Result.AddError(error.Build());
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ protected override async Task OnExecuteAsync(
RequestState state,
CancellationToken cancellationToken)
{
if (state.TryGetState(SelectionSet, out var executionState))
if (!state.TryGetState(SelectionSet, out var executionState))
{
return;
}

try
{
InitializeRequests(context, executionState);

Expand All @@ -82,6 +87,11 @@ protected override async Task OnExecuteAsync(
ProcessResult(context, response, batchExecutionState);
}
}
catch(Exception ex)
{
var error = context.OperationContext.ErrorHandler.CreateUnexpectedError(ex);
context.Result.AddError(error.Build());
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ private void ReadEntityConfig(
break;
}
}

_subgraphNames.Add(subgraph);

if(!_subgraphInfos.TryGetValue(subgraph, out var subgraphInfo))
{
Expand Down Expand Up @@ -402,6 +404,8 @@ private ArgumentVariableDefinition ReadArgumentVariableDefinition(
break;
}
}

_subgraphNames.Add(schemaName);

return new ArgumentVariableDefinition(name, schemaName, type, argumentName);
}
Expand Down Expand Up @@ -435,6 +439,8 @@ private FieldVariableDefinition ReadFieldVariableDefinition(
}
}

_subgraphNames.Add(schemaName);

return new FieldVariableDefinition(name, schemaName, select);
}

Expand Down Expand Up @@ -497,6 +503,8 @@ private ResolverDefinition ReadResolverDefinition(
break;
}
}

_subgraphNames.Add(subgraph);

FragmentSpreadNode? placeholder = null;
_assert.Clear();
Expand Down Expand Up @@ -538,7 +546,7 @@ static void OptionalArgs(HashSet<string> assert)
}
}

private Dictionary<string, ITypeNode>? ReadResolverArgumentDefinitions(
private static Dictionary<string, ITypeNode>? ReadResolverArgumentDefinitions(
IValueNode argumentDefinitions)
{
if (argumentDefinitions is NullValueNode)
Expand Down
51 changes: 50 additions & 1 deletion src/HotChocolate/Fusion/test/Core.Tests/ErrorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using HotChocolate.Fusion.Composition;
using HotChocolate.Fusion.Composition.Features;
using HotChocolate.Fusion.Shared;
using HotChocolate.Language;
using HotChocolate.Skimmed.Serialization;
using HotChocolate.Utilities;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -173,6 +174,54 @@ query ReformatIds {
await snapshot.MatchAsync();
}

[Fact]
public async Task Internal_Server_Error_On_Root_Field()
{
// arrange
using var demoProject = await DemoProject.CreateAsync();

// act
var executor = await new ServiceCollection()
.AddSingleton<IHttpClientFactory>(new ErrorFactory(demoProject.HttpClientFactory, "a"))
.AddSingleton(demoProject.WebSocketConnectionFactory)
.AddFusionGatewayServer()
.ConfigureFromDocument(
Parse(
"""
schema
@fusion(version: 1)
@transport(subgraph: "a", group: "a", location: "http:\/\/localhost\/graphql", kind: "HTTP") {
query: Query
mutation: Mutation
}

type Query {
a: Boolean!
@resolver(subgraph: "a", select: "{ a }")
}
"""))
.CoreBuilder
.ModifyRequestOptions(o => o.IncludeExceptionDetails = true)
.BuildRequestExecutorAsync();

var request = Parse(
"""
query A {
a
}
""");

// act
var result = await executor.ExecuteAsync(
QueryRequestBuilder
.New()
.SetQuery(request)
.Create());

// assert
result.MatchSnapshot();
}

private class ErrorFactory : IHttpClientFactory
{
private readonly IHttpClientFactory _innerFactory;
Expand Down Expand Up @@ -203,4 +252,4 @@ protected override Task<HttpResponseMessage> SendAsync(
=> Task.FromResult(new HttpResponseMessage(HttpStatusCode.InternalServerError));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"errors": [
{
"message": "Internal Execution Error"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0-preview.7.23375.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="8.0.0-preview.7.23375.4" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite" Version="8.0.0-preview.7" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3472,6 +3472,16 @@
"System.Threading.Tasks.Extensions": "4.5.4"
}
},
"Npgsql.EntityFrameworkCore.PostgreSQL.NetTopologySuite": {
"type": "Direct",
"requested": "[8.0.0-preview.7, )",
"resolved": "8.0.0-preview.7",
"contentHash": "sKFxUIzjZgRQIQEzBR99hBLRgclqgDd6VbgrAFdTLiscBwyDLJggQjC/K1XZhy9E1/ustPSWPapCfcVeFzXdjw==",
"dependencies": {
"Npgsql.EntityFrameworkCore.PostgreSQL": "8.0.0-preview.7",
"Npgsql.NetTopologySuite": "8.0.0-preview.4"
}
},
"Squadron.PostgreSql": {
"type": "Direct",
"requested": "[0.15.0, )",
Expand Down Expand Up @@ -3834,10 +3844,18 @@
},
"NetTopologySuite": {
"type": "Transitive",
"resolved": "2.0.0",
"contentHash": "3ajBClEI9wx2/DjjGmV52sHW1m52vLg8sdz1pJbTf5ySj1X90qehQs3v1DRwGo0F8UKj/Z2SjNhRN/6LroAkqg==",
"resolved": "2.5.0",
"contentHash": "5/+2O2ADomEdUn09mlSigACdqvAf0m/pVPGtIPEPQWnyrVykYY0NlfXLIdkMgi41kvH9kNrPqYaFBTZtHYH7Xw==",
"dependencies": {
"System.Memory": "4.5.3"
"System.Memory": "4.5.4"
}
},
"NetTopologySuite.IO.PostGis": {
"type": "Transitive",
"resolved": "2.1.0",
"contentHash": "3W8XTFz8iP6GQ5jDXK1/LANHiU+988k1kmmuPWNKcJLpmSg6CvFpbTpz+s4+LBzkAp64wHGOldSlkSuzYfrIKA==",
"dependencies": {
"NetTopologySuite": "[2.0.0, 3.0.0-A)"
}
},
"Newtonsoft.Json": {
Expand All @@ -3847,10 +3865,20 @@
},
"Npgsql": {
"type": "Transitive",
"resolved": "4.1.1",
"contentHash": "VvYSduwCVCy1erIntV3jVbBduAL8+hqobg8xf5xPmkqzGJ5j9Wx4y/eXz2+BLmFkozJEjTzxz8/X5cOyJ4P9Ig==",
"resolved": "8.0.0-preview.4",
"contentHash": "wvbiipddbRgaiYOij4fQYqnfDlxKz1XlpCNY7mWErF+CPmg+ujfs9u1ovx40TsV0Q7GKlgdyr6dugV15HvZ2Pw==",
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "4.6.0"
"Microsoft.Extensions.Logging.Abstractions": "6.0.0"
}
},
"Npgsql.NetTopologySuite": {
"type": "Transitive",
"resolved": "8.0.0-preview.4",
"contentHash": "rgVwnoFNA0bOT7EudZEZ4zRXQvETmomFermJJhYSPtY63LbjY84YNkvA7aC75a4oxF+997hbcNwNHKpp3TzoUw==",
"dependencies": {
"NetTopologySuite": "2.5.0",
"NetTopologySuite.IO.PostGIS": "2.1.0",
"Npgsql": "8.0.0-preview.4"
}
},
"NuGet.Frameworks": {
Expand Down
Loading