Skip to content

Commit d52c105

Browse files
tobias-tenglermichaelstaib
authored andcommitted
Do not apply @semanticNonNull to id fields (#8136)
1 parent fe3401c commit d52c105

File tree

4 files changed

+19
-36
lines changed

4 files changed

+19
-36
lines changed

src/HotChocolate/Core/src/Types/SemanticNonNullTypeInterceptor.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
using HotChocolate.Types.Descriptors;
99
using HotChocolate.Types.Descriptors.Definitions;
1010
using HotChocolate.Types.Helpers;
11-
using HotChocolate.Types.Relay;
1211
using HotChocolate.Utilities;
1312

1413
namespace HotChocolate;
1514

1615
internal sealed class SemanticNonNullTypeInterceptor : TypeInterceptor
1716
{
1817
private ITypeInspector _typeInspector = null!;
19-
private ExtendedTypeReference _nodeTypeReference = null!;
2018

2119
internal override bool IsEnabled(IDescriptorContext context)
2220
=> context.Options.EnableSemanticNonNull;
@@ -29,8 +27,6 @@ internal override void InitializeContext(
2927
TypeReferenceResolver typeReferenceResolver)
3028
{
3129
_typeInspector = context.TypeInspector;
32-
33-
_nodeTypeReference = _typeInspector.GetTypeRef(typeof(NodeType));
3430
}
3531

3632
/// <summary>
@@ -92,16 +88,14 @@ public override void OnAfterCompleteName(ITypeCompletionContext completionContex
9288
return;
9389
}
9490

95-
var implementsNode = objectDef.Interfaces.Any(i => i.Equals(_nodeTypeReference));
96-
9791
foreach (var field in objectDef.Fields)
9892
{
9993
if (field.IsIntrospectionField)
10094
{
10195
continue;
10296
}
10397

104-
if (implementsNode && field.Name == "id")
98+
if (field.Name == "id")
10599
{
106100
continue;
107101
}

src/HotChocolate/Core/test/Types.Tests/SemanticNonNullTests.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace HotChocolate;
1111
public class SemanticNonNullTests
1212
{
1313
[Fact]
14-
public async Task Object_Implementing_Node()
14+
public async Task Object_With_Id_Field()
1515
{
1616
await new ServiceCollection()
1717
.AddGraphQL()
@@ -20,8 +20,7 @@ public async Task Object_Implementing_Node()
2020
o.EnableSemanticNonNull = true;
2121
o.EnsureAllNodesCanBeResolved = false;
2222
})
23-
.AddQueryType<QueryWithNode>()
24-
.AddGlobalObjectIdentification()
23+
.AddQueryType<QueryWithTypeWithId>()
2524
.BuildSchemaAsync()
2625
.MatchSnapshotAsync();
2726
}
@@ -306,13 +305,12 @@ public class Foo
306305
}
307306

308307
[ObjectType("Query")]
309-
public class QueryWithNode
308+
public class QueryWithTypeWithId
310309
{
311-
public MyNode GetMyNode() => new(1);
310+
public MyType GetMyNode() => new(1);
312311
}
313312

314-
[Node]
315-
public record MyNode([property: ID] int Id);
313+
public record MyType([property: ID] int Id);
316314

317315
public class Mutation
318316
{

src/HotChocolate/Core/test/Types.Tests/__snapshots__/SemanticNonNullTests.Object_Implementing_Node.snap

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
schema {
2+
query: Query
3+
}
4+
5+
type MyType {
6+
id: ID!
7+
}
8+
9+
type Query {
10+
myNode: MyType @semanticNonNull
11+
}
12+
13+
directive @semanticNonNull(levels: [Int!] = [ 0 ]) on FIELD_DEFINITION

0 commit comments

Comments
 (0)