-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow empty filter expressions to be visited (#5214)
Co-authored-by: Pascal Senn <senn.pasc@gmail.com>
- Loading branch information
1 parent
4901fe6
commit b369d8c
Showing
30 changed files
with
313 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/HotChocolate/Data/test/Data.Filters.InMemory.Tests/QueryableFilterCombinatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Threading.Tasks; | ||
using CookieCrumble; | ||
using HotChocolate.Execution; | ||
|
||
namespace HotChocolate.Data.Filters; | ||
|
||
public class QueryableFilterCombinatorTests | ||
{ | ||
private static readonly Foo[] _fooEntities = | ||
{ | ||
new() { Bar = true }, | ||
new() { Bar = false } | ||
}; | ||
|
||
private readonly SchemaCache _cache = new(); | ||
|
||
[Fact] | ||
public async Task Create_Empty_Expression() | ||
{ | ||
// arrange | ||
var tester = _cache.CreateSchema<Foo, FooFilterInput>(_fooEntities); | ||
|
||
// act | ||
// assert | ||
var res1 = await tester.ExecuteAsync( | ||
QueryRequestBuilder.New() | ||
.SetQuery("{ root(where: { }){ bar }}") | ||
.Create()); | ||
|
||
await Snapshot.Create() | ||
.Add(res1) | ||
.MatchAsync(); | ||
} | ||
|
||
public class Foo | ||
{ | ||
public int Id { get; set; } | ||
|
||
public bool Bar { get; set; } | ||
} | ||
|
||
public class FooNullable | ||
{ | ||
public int Id { get; set; } | ||
|
||
public bool? Bar { get; set; } | ||
} | ||
|
||
public class FooFilterInput | ||
: FilterInputType<Foo> | ||
{ | ||
} | ||
|
||
public class FooNullableFilterInput | ||
: FilterInputType<FooNullable> | ||
{ | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
....InMemory.Tests/__snapshots__/QueryableFilterCombinatorTests.Create_Empty_Expression.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"data": { | ||
"root": [ | ||
{ | ||
"bar": true | ||
}, | ||
{ | ||
"bar": false | ||
} | ||
] | ||
} | ||
} |
17 changes: 11 additions & 6 deletions
17
...napshots__/QueryableFirstOrDefaultTests.Create_DeepFilterObjectTwoProjections_NET6_0.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
{ | ||
"errors": [ | ||
{ | ||
"message": "Unexpected Execution Error", | ||
"message": "The provided value for filter \u0060all\u0060 of type FooNestedFilterInput is invalid. Null values are not supported.", | ||
"locations": [ | ||
{ | ||
"line": 2, | ||
"column": 25 | ||
"line": 1, | ||
"column": 35 | ||
} | ||
], | ||
"path": [ | ||
"root" | ||
] | ||
], | ||
"extensions": { | ||
"code": "HC0026", | ||
"expectedType": "FooNestedFilterInput!", | ||
"filterType": "FooNestedFilterInput" | ||
} | ||
} | ||
], | ||
"data": { | ||
"root": null | ||
"root": [] | ||
} | ||
} | ||
} |
17 changes: 11 additions & 6 deletions
17
...napshots__/QueryableFirstOrDefaultTests.Create_DeepFilterObjectTwoProjections_NET7_0.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
{ | ||
"errors": [ | ||
{ | ||
"message": "Unexpected Execution Error", | ||
"message": "The provided value for filter \u0060all\u0060 of type FooNestedFilterInput is invalid. Null values are not supported.", | ||
"locations": [ | ||
{ | ||
"line": 2, | ||
"column": 25 | ||
"line": 1, | ||
"column": 35 | ||
} | ||
], | ||
"path": [ | ||
"root" | ||
] | ||
], | ||
"extensions": { | ||
"code": "HC0026", | ||
"expectedType": "FooNestedFilterInput!", | ||
"filterType": "FooNestedFilterInput" | ||
} | ||
} | ||
], | ||
"data": { | ||
"root": null | ||
"root": [] | ||
} | ||
} | ||
} |
17 changes: 11 additions & 6 deletions
17
...hots__/QueryableFirstOrDefaultTests.Create_ListObjectDifferentLevelProjection_NET6_0.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
{ | ||
"errors": [ | ||
{ | ||
"message": "Unexpected Execution Error", | ||
"message": "The provided value for filter \u0060all\u0060 of type FooNestedFilterInput is invalid. Null values are not supported.", | ||
"locations": [ | ||
{ | ||
"line": 2, | ||
"column": 25 | ||
"line": 1, | ||
"column": 35 | ||
} | ||
], | ||
"path": [ | ||
"root" | ||
] | ||
], | ||
"extensions": { | ||
"code": "HC0026", | ||
"expectedType": "FooNestedFilterInput!", | ||
"filterType": "FooNestedFilterInput" | ||
} | ||
} | ||
], | ||
"data": { | ||
"root": null | ||
"root": [] | ||
} | ||
} | ||
} |
17 changes: 11 additions & 6 deletions
17
...hots__/QueryableFirstOrDefaultTests.Create_ListObjectDifferentLevelProjection_NET7_0.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
{ | ||
"errors": [ | ||
{ | ||
"message": "Unexpected Execution Error", | ||
"message": "The provided value for filter \u0060all\u0060 of type FooNestedFilterInput is invalid. Null values are not supported.", | ||
"locations": [ | ||
{ | ||
"line": 2, | ||
"column": 25 | ||
"line": 1, | ||
"column": 35 | ||
} | ||
], | ||
"path": [ | ||
"root" | ||
] | ||
], | ||
"extensions": { | ||
"code": "HC0026", | ||
"expectedType": "FooNestedFilterInput!", | ||
"filterType": "FooNestedFilterInput" | ||
} | ||
} | ||
], | ||
"data": { | ||
"root": null | ||
"root": [] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/HotChocolate/MongoDb/src/Data/Driver/MongoDbFilterOperation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
using System; | ||
using System.Collections; | ||
using MongoDB.Bson; | ||
using MongoDB.Bson.IO; | ||
|
17 changes: 3 additions & 14 deletions
17
src/HotChocolate/MongoDb/src/Data/Extensions/MongoDbFilterScopeExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,17 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using MongoDB.Bson; | ||
using MongoDB.Driver; | ||
|
||
namespace HotChocolate.Data.MongoDb.Filters; | ||
|
||
public static class MongoDbFilterScopeExtensions | ||
{ | ||
public static string GetPath(this MongoDbFilterScope scope) => | ||
string.Join(".", scope.Path.Reverse()); | ||
|
||
public static bool TryCreateQuery( | ||
this MongoDbFilterScope scope, | ||
[NotNullWhen(true)] out MongoDbFilterDefinition? query) | ||
public static MongoDbFilterDefinition CreateQuery(this MongoDbFilterScope scope) | ||
{ | ||
query = null; | ||
|
||
if (scope.Level.Peek().Count == 0) | ||
{ | ||
return false; | ||
return MongoDbFilterDefinition.Empty; | ||
} | ||
|
||
query = new AndFilterDefinition(scope.Level.Peek().ToArray()); | ||
|
||
return true; | ||
return new AndFilterDefinition(scope.Level.Peek().ToArray()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.