Skip to content

Commit 50b559a

Browse files
authored
Fixed nullability on some type descriptors. (#8542)
1 parent 563fede commit 50b559a

File tree

6 files changed

+20
-24
lines changed

6 files changed

+20
-24
lines changed

src/HotChocolate/Core/src/Types/Types/Attributes/DefaultValueSyntaxAttribute.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,35 @@ public sealed class DefaultValueSyntaxAttribute : DescriptorAttribute
3333
/// <summary>
3434
/// Creates a new instance of <see cref="DefaultValueSyntaxAttribute"/>.
3535
/// </summary>
36-
public DefaultValueSyntaxAttribute(string? syntax)
36+
public DefaultValueSyntaxAttribute(string syntax)
3737
{
3838
Syntax = syntax;
3939
}
4040

4141
/// <summary>
4242
/// The GraphQL syntax of the default value.
4343
/// </summary>
44-
public string? Syntax { get; }
44+
public string Syntax { get; }
4545

4646
/// <inheritdoc />
4747
protected internal override void TryConfigure(
4848
IDescriptorContext context,
4949
IDescriptor descriptor,
5050
ICustomAttributeProvider element)
5151
{
52-
if (descriptor is IArgumentDescriptor arg)
52+
switch (descriptor)
5353
{
54-
arg.DefaultValueSyntax(Syntax);
55-
}
54+
case IArgumentDescriptor arg:
55+
arg.DefaultValueSyntax(Syntax);
56+
break;
5657

57-
if (descriptor is IDirectiveArgumentDescriptor darg)
58-
{
59-
darg.DefaultValueSyntax(Syntax);
60-
}
58+
case IDirectiveArgumentDescriptor arg:
59+
arg.DefaultValueSyntax(Syntax);
60+
break;
6161

62-
if (descriptor is IInputFieldDescriptor field)
63-
{
64-
field.DefaultValueSyntax(Syntax);
62+
case IInputFieldDescriptor arg:
63+
arg.DefaultValueSyntax(Syntax);
64+
break;
6565
}
6666
}
6767
}

src/HotChocolate/Core/src/Types/Types/Extensions/DirectiveTypeDescriptorExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class DirectiveTypeDescriptorExtensions
77
{
88
public static IDirectiveTypeDescriptor<T> Ignore<T>(
99
this IDirectiveTypeDescriptor<T> descriptor,
10-
Expression<Func<T, object>> property)
10+
Expression<Func<T, object?>> property)
1111
{
1212
ArgumentNullException.ThrowIfNull(descriptor);
1313
ArgumentNullException.ThrowIfNull(property);

src/HotChocolate/Core/src/Types/Types/Extensions/InputObjectTypeDescriptorExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using System.Linq.Expressions;
42
using HotChocolate.Language;
53
using System.Diagnostics.CodeAnalysis;
@@ -32,7 +30,7 @@ public static class InputObjectTypeDescriptorExtensions
3230
/// </exception>
3331
public static IInputObjectTypeDescriptor<T> Ignore<T>(
3432
this IInputObjectTypeDescriptor<T> descriptor,
35-
Expression<Func<T, object>> property)
33+
Expression<Func<T, object?>> property)
3634
{
3735
ArgumentNullException.ThrowIfNull(descriptor);
3836
ArgumentNullException.ThrowIfNull(property);

src/HotChocolate/Core/src/Types/Types/Extensions/InterfaceTypeDescriptorExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public static class InterfaceTypeDescriptorExtensions
77
{
88
public static IInterfaceTypeDescriptor<T> Ignore<T>(
99
this IInterfaceTypeDescriptor<T> descriptor,
10-
Expression<Func<T, object>> propertyOrMethod)
10+
Expression<Func<T, object?>> propertyOrMethod)
1111
{
1212
ArgumentNullException.ThrowIfNull(descriptor);
1313
ArgumentNullException.ThrowIfNull(propertyOrMethod);

src/HotChocolate/Core/src/Types/Types/Extensions/ObjectTypeDescriptorExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable disable
2-
31
using System.Linq.Expressions;
42
using HotChocolate.Language;
53

@@ -12,7 +10,7 @@ public static class ObjectTypeDescriptorExtensions
1210
{
1311
public static IObjectTypeDescriptor<T> Ignore<T>(
1412
this IObjectTypeDescriptor<T> descriptor,
15-
Expression<Func<T, object>> propertyOrMethod)
13+
Expression<Func<T, object?>> propertyOrMethod)
1614
{
1715
ArgumentNullException.ThrowIfNull(descriptor);
1816
ArgumentNullException.ThrowIfNull(propertyOrMethod);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public void Ignore_DescriptorIsNull_ArgumentNullException()
369369
// arrange
370370
// act
371371
void Action()
372-
=> InputObjectTypeDescriptorExtensions.Ignore<SimpleInput>(null, t => t.Id);
372+
=> InputObjectTypeDescriptorExtensions.Ignore<SimpleInput>(null!, t => t.Id);
373373

374374
// assert
375375
Assert.Throws<ArgumentNullException>(Action);
@@ -384,7 +384,7 @@ public void Ignore_ExpressionIsNull_ArgumentNullException()
384384
DescriptorContext.Create());
385385

386386
// act
387-
void Action() => descriptor.Ignore(null);
387+
void Action() => descriptor.Ignore(null!);
388388

389389
// assert
390390
Assert.Throws<ArgumentNullException>(Action);
@@ -721,15 +721,15 @@ input Foo {
721721
[Fact]
722722
public void OneOf_descriptor_is_null()
723723
{
724-
void Fail() => InputObjectTypeDescriptorExtensions.OneOf(null);
724+
void Fail() => InputObjectTypeDescriptorExtensions.OneOf(null!);
725725

726726
Assert.Throws<ArgumentNullException>(Fail);
727727
}
728728

729729
[Fact]
730730
public void OneOf_generic_descriptor_is_null()
731731
{
732-
void Fail() => InputObjectTypeDescriptorExtensions.OneOf<object>(null);
732+
void Fail() => InputObjectTypeDescriptorExtensions.OneOf<object>(null!);
733733

734734
Assert.Throws<ArgumentNullException>(Fail);
735735
}

0 commit comments

Comments
 (0)