Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Nov 14, 2024
1 parent e88b11a commit aca4e59
Show file tree
Hide file tree
Showing 11 changed files with 1,890 additions and 755 deletions.
2,405 changes: 1,693 additions & 712 deletions src/HotChocolate/Core/src/Types/Properties/TypeResources.Designer.cs

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions src/HotChocolate/Core/src/Types/Properties/TypeResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,4 @@ Type: `{0}`</value>
<data name="ObjectToDictionaryConverter_CycleInObjectGraph" xml:space="preserve">
<value>Cycle in object graph detected.</value>
</data>
<data name="SemanticNonNullDirectiveType_Description" xml:space="preserve">
<value></value>
</data>
<data name="SemanticNonNullDirectiveType_Levels_Description" xml:space="preserve">
<value></value>
</data>
</root>
11 changes: 11 additions & 0 deletions src/HotChocolate/Core/src/Types/SemanticNonNullTypeInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public override void OnAfterCompleteName(ITypeCompletionContext completionContex
return;
}

if (objectDef.Name is "CollectionSegmentInfo" or "PageInfo")
{
return;
}

var implementsNode = objectDef.Interfaces.Any(i => i.Equals(_nodeTypeReference));

foreach (var field in objectDef.Fields)
Expand Down Expand Up @@ -306,6 +311,12 @@ private static void CheckResultForSemanticNonNullViolations(object? result, IRes

if (result is IEnumerable enumerable)
{
if (currentLevel >= 32)
{
// We bail if we're at a depth of 32 as this would mean that we're dealing with an AnyType or another structure.
return;
}

var index = 0;
foreach (var item in enumerable)
{
Expand Down
61 changes: 56 additions & 5 deletions src/HotChocolate/Core/test/Execution.Tests/SemanticNonNullTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace HotChocolate.Execution;

// TODO: Test nested arrays, pagination
public class SemanticNonNullTests
{
#region Scalar
Expand Down Expand Up @@ -775,9 +774,56 @@ public async Task Mutation_With_MutationConventions()
result.MatchSnapshot();
}

// TODO: Rename
[Fact]
public async Task Test()
public async Task Query_With_Connection()
{
var result = await new ServiceCollection()
.AddGraphQL()
.ModifyOptions(o =>
{
o.EnableSemanticNonNull = true;
})
.AddMutationConventions()
.AddQueryType<Query>()
.ExecuteRequestAsync("""
{
scalarConnection {
edges {
node
}
}
}
""");

result.MatchSnapshot();
}

[Fact]
public async Task Query_With_NullableConnectionNodes()
{
var result = await new ServiceCollection()
.AddGraphQL()
.ModifyOptions(o =>
{
o.EnableSemanticNonNull = true;
})
.AddMutationConventions()
.AddQueryType<Query>()
.ExecuteRequestAsync("""
{
nullableScalarConnection {
edges {
node
}
}
}
""");

result.MatchSnapshot();
}

[Fact]
public async Task Pure_Scalar_ListOfList_Nullable_Outer_And_Inner_Middle_Returns_Null_Should_Null_And_Error()
{
var result = await new ServiceCollection()
.AddGraphQL()
Expand All @@ -796,9 +842,8 @@ public async Task Test()
result.MatchSnapshot();
}

// TODO: Rename
[Fact]
public async Task Test2()
public async Task Pure_Scalar_ListOfList_Nullable_Middle_Item_Outer_And_Inner_Return_Null_Should_Null_And_Error()
{
var result = await new ServiceCollection()
.AddGraphQL()
Expand Down Expand Up @@ -989,6 +1034,12 @@ public Task<SomeObject[]> ObjectListItemThrowingError(IResolverContext context)
return [["a1", null!, "c1"], null!, ["a2", null!, "c2"]];
}
#endregion

[UsePaging]
public string[] ScalarConnection() => new[] { "a", null!, "c" };

[UsePaging]
public string?[] NullableScalarConnection() => new[] { "a", null, "c" };
}

public record SomeObject(string Property);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"errors": [
{
"message": "Unexpected Execution Error",
"locations": [
{
"line": 4,
"column": 7
}
],
"path": [
"scalarConnection",
"edges",
1,
"node"
]
}
],
"data": {
"scalarConnection": {
"edges": [
{
"node": "a"
},
{
"node": null
},
{
"node": "c"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"data": {
"nullableScalarConnection": {
"edges": [
{
"node": "a"
},
{
"node": null
},
{
"node": "c"
}
]
}
}
}

This file was deleted.

24 changes: 23 additions & 1 deletion src/HotChocolate/Core/test/Types.Tests/SemanticNonNullTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace HotChocolate;

// TODO: Test paginatino
public class SemanticNonNullTests
{
[Fact]
Expand Down Expand Up @@ -43,6 +42,20 @@ public async Task MutationConventions()
.MatchSnapshotAsync();
}

[Fact]
public async Task Pagination()
{
await new ServiceCollection()
.AddGraphQL()
.ModifyOptions(o =>
{
o.EnableSemanticNonNull = true;
})
.AddQueryType<QueryWithPagination>()
.BuildSchemaAsync()
.MatchSnapshotAsync();
}

[Fact]
public async Task Derive_SemanticNonNull_From_ImplementationFirst()
{
Expand Down Expand Up @@ -309,4 +322,13 @@ public class Mutation
}

public class MyException : Exception;

public class QueryWithPagination
{
[UsePaging]
public string[] GetCursorPagination() => [];

[UseOffsetPaging]
public string[] GetOffsetPagination() => [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
schema {
query: QueryWithPagination
}

"Information about the offset pagination."
type CollectionSegmentInfo {
"Indicates whether more items exist following the set defined by the clients arguments."
hasNextPage: Boolean!
"Indicates whether more items exist prior the set defined by the clients arguments."
hasPreviousPage: Boolean!
}

"A connection to a list of items."
type CursorPaginationConnection {
"Information to aid in pagination."
pageInfo: PageInfo @semanticNonNull
"A list of edges."
edges: [CursorPaginationEdge] @semanticNonNull(levels: [ 1 ])
"A flattened list of the nodes."
nodes: [String] @semanticNonNull(levels: [ 1 ])
}

"An edge in a connection."
type CursorPaginationEdge {
"A cursor for use in pagination."
cursor: String @semanticNonNull
"The item at the end of the edge."
node: String @semanticNonNull
}

"A segment of a collection."
type OffsetPaginationCollectionSegment {
"Information to aid in pagination."
pageInfo: CollectionSegmentInfo @semanticNonNull
"A flattened list of the items."
items: [String] @semanticNonNull(levels: [ 1 ])
}

"Information about pagination in a connection."
type PageInfo {
"Indicates whether more edges exist following the set defined by the clients arguments."
hasNextPage: Boolean!
"Indicates whether more edges exist prior the set defined by the clients arguments."
hasPreviousPage: Boolean!
"When paginating backwards, the cursor to continue."
startCursor: String
"When paginating forwards, the cursor to continue."
endCursor: String
}

type QueryWithPagination {
cursorPagination("Returns the first _n_ elements from the list." first: Int "Returns the elements in the list that come after the specified cursor." after: String "Returns the last _n_ elements from the list." last: Int "Returns the elements in the list that come before the specified cursor." before: String): CursorPaginationConnection
offsetPagination(skip: Int take: Int): OffsetPaginationCollectionSegment
}

directive @semanticNonNull(levels: [Int!] = [ 0 ]) on FIELD_DEFINITION

0 comments on commit aca4e59

Please sign in to comment.