Skip to content

Commit 8d63d28

Browse files
committed
[Fusion] Fixed introspection fields are no longer printet into the SDL
1 parent 996aaa8 commit 8d63d28

File tree

8 files changed

+143
-13
lines changed

8 files changed

+143
-13
lines changed

src/HotChocolate/AspNetCore/src/AspNetCore.Pipeline/HttpGetSchemaMiddleware.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private bool IsSchemaPath(HttpRequest request)
7171
return false;
7272
}
7373

74-
private async Task HandleRequestAsync(HttpContext context, ExecutorSession session, GraphQLServerOptions options)
74+
private static async Task HandleRequestAsync(HttpContext context, ExecutorSession session, GraphQLServerOptions options)
7575
{
7676
if (!options.EnableSchemaFileSupport)
7777
{
@@ -101,7 +101,7 @@ await session.WriteResultAsync(
101101
}
102102
}
103103

104-
private async Task WriteTypesAsync(
104+
private static async Task WriteTypesAsync(
105105
HttpContext context,
106106
ExecutorSession session,
107107
string typeNames,
@@ -141,7 +141,7 @@ await session.WriteResultAsync(
141141
await PrintTypesAsync(types, context.Response.Body, indent, context.RequestAborted);
142142
}
143143

144-
private string GetTypesFileName(List<ITypeDefinition> types)
144+
private static string GetTypesFileName(List<ITypeDefinition> types)
145145
=> types.Count == 1
146146
? $"{types[0].Name}.graphql"
147147
: "types.graphql";

src/HotChocolate/Core/src/Types.Abstractions/Types/IOutputFieldDefinition.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ public interface IOutputFieldDefinition : IFieldDefinition
1414
/// </summary>
1515
IReadOnlyFieldDefinitionCollection<IInputValueDefinition> Arguments { get; }
1616

17+
/// <summary>
18+
/// Gets or sets the type of the field.
19+
/// </summary>
20+
new IOutputType Type { get; }
21+
1722
/// <summary>
1823
/// Creates a <see cref="FieldDefinitionNode"/> from the current <see cref="IOutputFieldDefinition"/>.
1924
/// </summary>
2025
/// <returns>
2126
/// Returns a <see cref="FieldDefinitionNode"/>.
2227
/// </returns>
2328
new FieldDefinitionNode ToSyntaxNode();
24-
25-
/// <summary>
26-
/// Gets or sets the type of the field.
27-
/// </summary>
28-
new IOutputType Type { get; }
2929
}

src/HotChocolate/Core/src/Types.Abstractions/Types/SchemaVisitor.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ public virtual void VisitTypes(
1414
{
1515
foreach (var type in typesDefinition)
1616
{
17+
if (type.IsIntrospectionType)
18+
{
19+
continue;
20+
}
21+
1722
VisitType(type, context);
1823
}
1924
}
@@ -154,6 +159,11 @@ public virtual void VisitOutputFields(
154159
{
155160
foreach (var field in fields)
156161
{
162+
if (field.IsIntrospectionField)
163+
{
164+
continue;
165+
}
166+
157167
VisitOutputField(field, context);
158168
}
159169
}

src/HotChocolate/Fusion-vnext/src/Fusion.Execution.Types/FusionOutputFieldDefinition.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public FusionOutputFieldDefinition(
2222
Name = name;
2323
Description = description;
2424
IsDeprecated = isDeprecated;
25+
IsIntrospectionField = name.StartsWith("__");
2526
DeprecationReason = deprecationReason;
2627
Arguments = arguments;
2728

@@ -56,6 +57,8 @@ private set
5657

5758
public bool IsDeprecated { get; }
5859

60+
public bool IsIntrospectionField { get; }
61+
5962
public string? DeprecationReason { get; }
6063

6164
public FusionDirectiveCollection Directives

src/HotChocolate/Fusion-vnext/src/Fusion.Execution.Types/Serialization/SchemaFormatter.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public override void VisitTypes(
170170

171171
foreach (var type in typesDefinition
172172
.OfType<IObjectTypeDefinition>()
173+
.Where(t => !t.IsIntrospectionType)
173174
.OrderBy(t => t.Name))
174175
{
175176
if (context.Schema?.QueryType == type
@@ -185,6 +186,7 @@ public override void VisitTypes(
185186

186187
foreach (var type in typesDefinition
187188
.OfType<IInterfaceTypeDefinition>()
189+
.Where(t => !t.IsIntrospectionType)
188190
.OrderBy(t => t.Name))
189191
{
190192
VisitType(type, context);
@@ -193,6 +195,7 @@ public override void VisitTypes(
193195

194196
foreach (var type in typesDefinition
195197
.OfType<IUnionTypeDefinition>()
198+
.Where(t => !t.IsIntrospectionType)
196199
.OrderBy(t => t.Name))
197200
{
198201
VisitType(type, context);
@@ -201,6 +204,7 @@ public override void VisitTypes(
201204

202205
foreach (var type in typesDefinition
203206
.OfType<IInputObjectTypeDefinition>()
207+
.Where(t => !t.IsIntrospectionType)
204208
.OrderBy(t => t.Name))
205209
{
206210
VisitType(type, context);
@@ -209,6 +213,7 @@ public override void VisitTypes(
209213

210214
foreach (var type in typesDefinition
211215
.OfType<IEnumTypeDefinition>()
216+
.Where(t => !t.IsIntrospectionType)
212217
.OrderBy(t => t.Name))
213218
{
214219
VisitType(type, context);
@@ -217,6 +222,7 @@ public override void VisitTypes(
217222

218223
foreach (var type in typesDefinition
219224
.OfType<IScalarTypeDefinition>()
225+
.Where(t => !t.IsIntrospectionType)
220226
.OrderBy(t => t.Name))
221227
{
222228
if (!context.PrintSpecScalars
@@ -402,6 +408,11 @@ public override void VisitOutputFields(
402408

403409
foreach (var field in fields.AsEnumerable().OrderBy(t => t.Name, context.OrderByName))
404410
{
411+
if (field.IsIntrospectionField)
412+
{
413+
continue;
414+
}
415+
405416
VisitOutputField(field, context);
406417
fieldNodes.Add((FieldDefinitionNode)context.Result!);
407418
}

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Buffers;
22
using System.Diagnostics;
33
using System.IO.Hashing;
4+
using System.Reactive.Disposables;
45
using System.Text;
56
using HotChocolate.Fusion.Diagnostics;
67
using HotChocolate.Fusion.Execution.Clients;
@@ -362,13 +363,16 @@ public async ValueTask<bool> MoveNextAsync()
362363
}
363364

364365
bool hasResult;
365-
var scope = _diagnosticEvents.ExecuteSubscriptionEvent(_context, _node);
366-
var start = Stopwatch.GetTimestamp();
366+
IDisposable? scope = null;
367+
long? start = null;
367368

368369
try
369370
{
370371
hasResult = await _resultEnumerator.MoveNextAsync();
371372

373+
scope = _diagnosticEvents.ExecuteSubscriptionEvent(_context, _node);
374+
start = Stopwatch.GetTimestamp();
375+
372376
if (hasResult)
373377
{
374378
_resultBuffer[0] = _resultEnumerator.Current;
@@ -383,8 +387,8 @@ public async ValueTask<bool> MoveNextAsync()
383387
_node.Id,
384388
Activity.Current,
385389
ExecutionStatus.Failed,
386-
scope,
387-
start,
390+
scope ?? Disposable.Empty,
391+
start ?? Stopwatch.GetTimestamp(),
388392
Stopwatch.GetTimestamp(),
389393
Exception: ex);
390394
return true;
@@ -397,7 +401,7 @@ public async ValueTask<bool> MoveNextAsync()
397401
Activity.Current,
398402
ExecutionStatus.Failed,
399403
scope,
400-
start,
404+
start.Value,
401405
Stopwatch.GetTimestamp());
402406
return true;
403407
}

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,34 @@ public async Task Typename_On_Object_With_Alias()
299299
response.MatchSnapshot();
300300
}
301301

302+
[Fact]
303+
public async Task Download_Schema()
304+
{
305+
// arrange
306+
using var server1 = CreateSourceSchema(
307+
"A",
308+
b => b.AddQueryType<SourceSchema1.Query>());
309+
310+
using var server2 = CreateSourceSchema(
311+
"B",
312+
b => b.AddQueryType<SourceSchema2.Query>());
313+
314+
using var gateway = await CreateCompositeSchemaAsync(
315+
[
316+
("A", server1),
317+
("B", server2),
318+
]);
319+
320+
// act
321+
using var client = gateway.CreateClient();
322+
323+
using var result = await client.GetAsync("http://localhost:5000/graphql/schema");
324+
var sdl = await result.Content.ReadAsStringAsync();
325+
326+
// assert
327+
sdl.MatchSnapshot(extension: ".graphql");
328+
}
329+
302330
public static class SourceSchema1
303331
{
304332
public record Book(int Id, string Title, Author Author);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
schema {
2+
query: Query
3+
}
4+
5+
type Query {
6+
authors("Returns the elements in the list that come after the specified cursor." after: String "Returns the elements in the list that come before the specified cursor." before: String "Returns the first _n_ elements from the list." first: Int "Returns the last _n_ elements from the list." last: Int): AuthorsConnection
7+
bookById(id: Int!): Book!
8+
books("Returns the elements in the list that come after the specified cursor." after: String "Returns the elements in the list that come before the specified cursor." before: String "Returns the first _n_ elements from the list." first: Int "Returns the last _n_ elements from the list." last: Int): BooksConnection
9+
}
10+
11+
type Author {
12+
books: [Book!]!
13+
id: Int!
14+
name: String!
15+
}
16+
17+
"A connection to a list of items."
18+
type AuthorsConnection {
19+
"A list of edges."
20+
edges: [AuthorsEdge!]
21+
"A flattened list of the nodes."
22+
nodes: [Author!]
23+
"Information to aid in pagination."
24+
pageInfo: PageInfo!
25+
}
26+
27+
"An edge in a connection."
28+
type AuthorsEdge {
29+
"A cursor for use in pagination."
30+
cursor: String!
31+
"The item at the end of the edge."
32+
node: Author!
33+
}
34+
35+
type Book {
36+
author: Author!
37+
id: Int!
38+
title: String!
39+
}
40+
41+
"A connection to a list of items."
42+
type BooksConnection {
43+
"A list of edges."
44+
edges: [BooksEdge!]
45+
"A flattened list of the nodes."
46+
nodes: [Book!]
47+
"Information to aid in pagination."
48+
pageInfo: PageInfo!
49+
}
50+
51+
"An edge in a connection."
52+
type BooksEdge {
53+
"A cursor for use in pagination."
54+
cursor: String!
55+
"The item at the end of the edge."
56+
node: Book!
57+
}
58+
59+
"Information about pagination in a connection."
60+
type PageInfo {
61+
"When paginating forwards, the cursor to continue."
62+
endCursor: String
63+
"Indicates whether more edges exist following the set defined by the clients arguments."
64+
hasNextPage: Boolean!
65+
"Indicates whether more edges exist prior the set defined by the clients arguments."
66+
hasPreviousPage: Boolean!
67+
"When paginating backwards, the cursor to continue."
68+
startCursor: String
69+
}
70+
71+
enum fusion__Schema {
72+
A
73+
B
74+
}

0 commit comments

Comments
 (0)