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

Fix issue with nullability inference of nested types. #6230

Merged
merged 3 commits into from
Jun 2, 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
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ internal static bool CollectNullability(
}

written = buffer.Length;
return false;
return true;
}
}
}
36 changes: 36 additions & 0 deletions src/HotChocolate/Core/test/Types.Tests/CodeFirstTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ public async Task Allow_PascalCasedArguments()
""");
}

[Fact]
public async Task Infer_Nullability_From_Nested_Classes()
{
var schema =
await new ServiceCollection()
.AddGraphQLServer()
.AddQueryType<QueryNestedClassNullableString>()
.BuildSchemaAsync();

schema.MatchSnapshot();
}

public class Query
{
public string SayHello(string name) =>
Expand Down Expand Up @@ -324,4 +336,28 @@ public class PascalCaseQuery
{
public string TestResolver(string TestArgument) => "abc";
}

public sealed class QueryNestedClassNullableString
{
public class Outer
{
public string? shouldBeNullable { get; set; }
}

public class Example
{
public class Inner
{
public string? shouldAlsoBeNullable { get; set; }
}

public Inner? inner { get; set; } = new();
public Outer? outer { get; set; } = new();
}

public Example NestedClassNullableString()
{
return new Example();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,19 @@ public void From_IExecutableScalar()
Assert.True(dict.IsArrayOrList);
}

[Fact]
public void Nested_Nullability()
{
// arrange
// act
var extendedType = ExtendedType.FromMember(
typeof(Nullability).GetMember("NestedProp").Single(),
_cache);

// assert
Assert.True(extendedType.IsNullable);
}

private sealed class CustomStringList1
: List<string>
{
Expand Down Expand Up @@ -415,6 +428,13 @@ public class Nullability

public Optional<Nullable<Optional<string?>>> OptionalNullableOptionalNullableString() =>
throw new NotImplementedException();

public Nested? NestedProp { get; set; }

public class Nested
{
public string? Value { get; set; }
}
}

#nullable disable
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
schema {
query: QueryNestedClassNullableString
}

type Example {
inner: Inner!
outer: Outer!
}

type Inner {
shouldAlsoBeNullable: String!
}

type Outer {
shouldBeNullable: String!
}

type QueryNestedClassNullableString {
nestedClassNullableString: Example!
}