Skip to content

Commit

Permalink
Add simple test
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Feb 10, 2024
1 parent ef8d1b3 commit 8157dc5
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 16 deletions.
58 changes: 42 additions & 16 deletions src/HotChocolate/Core/test/Execution.Tests/TrueNullabilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public async Task Schema_Without_TrueNullability()
.AddQueryType<Query>()
.ModifyOptions(o => o.EnableTrueNullability = false)
.BuildSchemaAsync();

schema.MatchSnapshot();
}

[Fact]
public async Task Schema_With_TrueNullability()
{
Expand All @@ -28,10 +28,10 @@ public async Task Schema_With_TrueNullability()
.AddQueryType<Query>()
.ModifyOptions(o => o.EnableTrueNullability = true)
.BuildSchemaAsync();

schema.MatchSnapshot();
}

[Fact]
public async Task Error_Query_With_TrueNullability_And_NullBubbling_Enabled_By_Default()
{
Expand All @@ -51,10 +51,10 @@ public async Task Error_Query_With_TrueNullability_And_NullBubbling_Enabled_By_D
}
}
""");

response.MatchSnapshot();
}

[Fact]
public async Task Error_Query_With_TrueNullability_And_NullBubbling_Enabled()
{
Expand All @@ -74,10 +74,10 @@ query @nullBubbling {
}
}
""");

response.MatchSnapshot();
}

[Fact]
public async Task Error_Query_With_TrueNullability_And_NullBubbling_Disabled()
{
Expand All @@ -97,10 +97,10 @@ query @nullBubbling(enable: false) {
}
}
""");

response.MatchSnapshot();
}

[Fact]
public async Task Error_Query_With_TrueNullability_And_NullBubbling_Disabled_With_Variable()
{
Expand All @@ -124,24 +124,50 @@ public async Task Error_Query_With_TrueNullability_And_NullBubbling_Disabled_Wit
""")
.SetVariableValue("enable", false)
.Create());


response.MatchSnapshot();
}

[Fact]
public async Task Error_Query_With_NullBubbling_Disabled()
{
var request = QueryRequestBuilder.New()
.SetQuery("""
query {
book {
name
author {
name
}
}
}
""")
.TryAddGlobalState(WellKnownContextData.DisableNullBubbling, true)
.Create();

var response =
await new ServiceCollection()
.AddGraphQLServer()
.AddQueryType<Query>()
.ExecuteRequestAsync(request);

response.MatchSnapshot();
}

public class Query
{
public Book? GetBook() => new();
}

public class Book
{
public string Name => "Some book!";

public Author Author => new();
}

public class Author
{
public string Name => throw new Exception();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"errors": [
{
"message": "Unexpected Execution Error",
"locations": [
{
"line": 5,
"column": 13
}
],
"path": [
"book",
"author",
"name"
]
}
],
"data": {
"book": {
"name": "Some book!",
"author": {
"name": null
}
}
}
}

0 comments on commit 8157dc5

Please sign in to comment.