Skip to content

Commit 44bf457

Browse files
authored
Fixed issue when sealing selections (#8426)
1 parent a0866ea commit 44bf457

File tree

3 files changed

+53
-89
lines changed

3 files changed

+53
-89
lines changed

src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Execution/Nodes/SelectionSet.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,10 @@ internal void Seal(Operation operation)
4848

4949
_isSealed = true;
5050
DeclaringOperation = operation;
51+
52+
foreach (var selection in Selections)
53+
{
54+
selection.Seal(this);
55+
}
5156
}
5257
}

src/HotChocolate/Fusion-vnext/test/Fusion.AspNetCore.Tests/FusionTestBase.cs

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,17 @@
1-
using System.Diagnostics.CodeAnalysis;
21
using HotChocolate.Execution;
32
using HotChocolate.Execution.Configuration;
4-
using HotChocolate.Fusion.Configuration;
5-
using HotChocolate.Fusion.Execution;
6-
using HotChocolate.Fusion.Execution.Nodes;
73
using HotChocolate.Fusion.Logging;
8-
using HotChocolate.Fusion.Planning;
9-
using HotChocolate.Fusion.Rewriters;
10-
using HotChocolate.Fusion.Types;
11-
using HotChocolate.Language;
124
using Microsoft.AspNetCore.Builder;
135
using Microsoft.AspNetCore.TestHost;
146
using Microsoft.Extensions.DependencyInjection;
15-
using Microsoft.Extensions.ObjectPool;
167

178
namespace HotChocolate.Fusion;
189

1910
public abstract class FusionTestBase : IDisposable
2011
{
21-
private readonly TestServerSession _testServerSession = new();
12+
internal readonly TestServerSession _testServerSession = new();
2213
private bool _disposed;
2314

24-
protected static FusionSchemaDefinition CreateCompositeSchema()
25-
{
26-
var compositeSchemaDoc = Utf8GraphQLParser.Parse(FileResource.Open("fusion1.graphql"));
27-
return FusionSchemaDefinition.Create(compositeSchemaDoc);
28-
}
29-
30-
protected static FusionSchemaDefinition CreateCompositeSchema(
31-
[StringSyntax("graphql")] string schema)
32-
{
33-
var compositeSchemaDoc = Utf8GraphQLParser.Parse(schema);
34-
return FusionSchemaDefinition.Create(compositeSchemaDoc);
35-
}
36-
37-
protected static FusionSchemaDefinition ComposeSchema(
38-
[StringSyntax("graphql")] params string[] schemas)
39-
{
40-
var compositionLog = new CompositionLog();
41-
var composer = new SchemaComposer(schemas, compositionLog);
42-
var result = composer.Compose();
43-
44-
if (!result.IsSuccess)
45-
{
46-
throw new InvalidOperationException(result.Errors[0].Message);
47-
}
48-
49-
var compositeSchemaDoc = result.Value.ToSyntaxNode();
50-
return FusionSchemaDefinition.Create(compositeSchemaDoc);
51-
}
52-
53-
protected static DocumentNode ComposeSchemaDocument(
54-
[StringSyntax("graphql")] params string[] schemas)
55-
{
56-
var compositionLog = new CompositionLog();
57-
var composer = new SchemaComposer(schemas, compositionLog);
58-
var result = composer.Compose();
59-
60-
if (!result.IsSuccess)
61-
{
62-
throw new InvalidOperationException(result.Errors[0].Message);
63-
}
64-
65-
return result.Value.ToSyntaxNode();
66-
}
67-
6815
public TestServer CreateSourceSchema(
6916
string schemaName,
7017
Action<IRequestExecutorBuilder> configureBuilder,
@@ -141,33 +88,6 @@ public async Task<TestServer> CreateCompositeSchemaAsync(
14188
configureApplication);
14289
}
14390

144-
protected static OperationExecutionPlan PlanOperation(
145-
FusionSchemaDefinition schema,
146-
[StringSyntax("graphql")] string operationText)
147-
{
148-
var pool = new DefaultObjectPool<OrderedDictionary<string, List<FieldSelectionNode>>>(
149-
new DefaultPooledObjectPolicy<OrderedDictionary<string, List<FieldSelectionNode>>>());
150-
151-
var operationDoc = Utf8GraphQLParser.Parse(operationText);
152-
153-
var rewriter = new InlineFragmentOperationRewriter(schema);
154-
var rewritten = rewriter.RewriteDocument(operationDoc, operationName: null);
155-
var operation = rewritten.Definitions.OfType<OperationDefinitionNode>().First();
156-
157-
var compiler = new OperationCompiler(schema, pool);
158-
var planner = new OperationPlanner(schema, compiler);
159-
return planner.CreatePlan("123", operation);
160-
}
161-
162-
protected static void MatchInline(
163-
OperationExecutionPlan plan,
164-
[StringSyntax("yaml")] string expected)
165-
{
166-
var formatter = new YamlExecutionPlanFormatter();
167-
var actual = formatter.Format(plan);
168-
actual.MatchInlineSnapshot(expected + Environment.NewLine);
169-
}
170-
17191
public void Dispose()
17292
{
17393
if (_disposed)

src/HotChocolate/Fusion-vnext/test/Fusion.AspNetCore.Tests/IntegrationTests.cs

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
using System.Text;
2-
using HotChocolate.Buffers;
3-
using HotChocolate.Types;
4-
using HotChocolate.Execution;
5-
using HotChocolate.Transport.Formatters;
61
using HotChocolate.Transport.Http;
7-
using Microsoft.AspNetCore.TestHost;
2+
using HotChocolate.Types;
3+
using Microsoft.AspNetCore.Builder;
84
using Microsoft.Extensions.DependencyInjection;
9-
using Microsoft.Extensions.DependencyInjection.Extensions;
105

116
namespace HotChocolate.Fusion;
127

@@ -21,7 +16,7 @@ public async Task Foo()
2116
b => b.AddQueryType(
2217
d => d.Name("Query")
2318
.Field("foo")
24-
.Resolve("foo")) );
19+
.Resolve("foo")));
2520

2621
using var server2 = CreateSourceSchema(
2722
"B",
@@ -51,4 +46,48 @@ public async Task Foo()
5146
using var response = await result.ReadAsResultAsync();
5247
response.MatchSnapshot();
5348
}
49+
50+
[Fact]
51+
public async Task Bar()
52+
{
53+
var server = _testServerSession.CreateServer(
54+
services =>
55+
{
56+
services.AddRouting();
57+
58+
services
59+
.AddHttpClient("SUBGRAPH1", c => c.BaseAddress = new Uri("http://localhost:5095/graphql"));
60+
61+
services
62+
.AddHttpClient("SUBGRAPH2", c => c.BaseAddress = new Uri("http://localhost:5096/graphql"));
63+
64+
services
65+
.AddGraphQLGatewayServer()
66+
.AddFileSystemConfiguration("/Users/michael/local/play/FusionServer/Gateway/gateway.graphql")
67+
.AddHttpClientConfiguration("SUBGRAPH1", new Uri("http://localhost:5095/graphql"))
68+
.AddHttpClientConfiguration("SUBGRAPH2", new Uri("http://localhost:5096/graphql"));
69+
},
70+
app =>
71+
{
72+
app.UseWebSockets();
73+
app.UseRouting();
74+
app.UseEndpoints(endpoint => endpoint.MapGraphQL());
75+
});
76+
77+
using var client = GraphQLHttpClient.Create(server.CreateClient());
78+
79+
using var result = await client.PostAsync(
80+
"""
81+
{
82+
book {
83+
title
84+
}
85+
}
86+
""",
87+
new Uri("http://localhost:5000/graphql"));
88+
89+
// act
90+
using var response = await result.ReadAsResultAsync();
91+
response.MatchSnapshot();
92+
}
5493
}

0 commit comments

Comments
 (0)