Skip to content

Commit 6e5595f

Browse files
Added DataLoader integration test with aliased filtering (#8489)
Co-authored-by: Michael Staib <[email protected]>
1 parent 94c7336 commit 6e5595f

File tree

3 files changed

+127
-0
lines changed

3 files changed

+127
-0
lines changed

src/HotChocolate/Data/test/Data.Filters.SqlServer.Tests/DataLoaderTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,45 @@ public async Task Filter_With_Filtering()
119119
.MatchMarkdownSnapshot();
120120
}
121121

122+
[Fact]
123+
public async Task Filter_With_Aliased_Filtering()
124+
{
125+
// Arrange
126+
var queries = new List<string>();
127+
var context = new CatalogContext();
128+
await context.SeedAsync();
129+
130+
// Act
131+
var result = await new ServiceCollection()
132+
.AddScoped(_ => queries)
133+
.AddTransient(_ => context)
134+
.AddGraphQL()
135+
.AddFiltering()
136+
.AddQueryType<Query>()
137+
.AddPagingArguments()
138+
.ModifyRequestOptions(o => o.IncludeExceptionDetails = true)
139+
.ExecuteRequestAsync(
140+
"""
141+
{
142+
a: filterContext(brandId: 1, where: { name: { startsWith: "Product" } }) {
143+
name
144+
}
145+
b: filterContext(brandId: 1, where: { name: { eq: "Product 0-0" } }) {
146+
name
147+
}
148+
}
149+
""");
150+
151+
Snapshot
152+
.Create(
153+
postFix: TestEnvironment.TargetFramework == "NET10_0"
154+
? TestEnvironment.TargetFramework
155+
: null)
156+
.AddSql(queries)
157+
.AddResult(result)
158+
.MatchMarkdownSnapshot();
159+
}
160+
122161
[Fact]
123162
public async Task Filter_With_Expression_Null()
124163
{
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Filter_With_Aliased_Filtering
2+
3+
## SQL
4+
5+
```text
6+
.param set @__keys_0 '[1]'
7+
.param set @__p_1_rewritten 'Product%'
8+
9+
SELECT "p"."Id", "p"."AvailableStock", "p"."BrandId", "p"."Description", "p"."ImageFileName", "p"."MaxStockThreshold", "p"."Name", "p"."OnReorder", "p"."Price", "p"."RestockThreshold", "p"."TypeId"
10+
FROM "Products" AS "p"
11+
WHERE "p"."BrandId" IN (
12+
SELECT "k"."value"
13+
FROM json_each(@__keys_0) AS "k"
14+
) AND "p"."Name" LIKE @__p_1_rewritten ESCAPE '\'
15+
.param set @__keys_0 '[1]'
16+
.param set @__p_1 'Product 0-0'
17+
18+
SELECT "p"."Id", "p"."AvailableStock", "p"."BrandId", "p"."Description", "p"."ImageFileName", "p"."MaxStockThreshold", "p"."Name", "p"."OnReorder", "p"."Price", "p"."RestockThreshold", "p"."TypeId"
19+
FROM "Products" AS "p"
20+
WHERE "p"."BrandId" IN (
21+
SELECT "k"."value"
22+
FROM json_each(@__keys_0) AS "k"
23+
) AND "p"."Name" = @__p_1
24+
```
25+
26+
## Result
27+
28+
```json
29+
{
30+
"data": {
31+
"a": [
32+
{
33+
"name": "Product 0-0"
34+
}
35+
],
36+
"b": [
37+
{
38+
"name": "Product 0-0"
39+
}
40+
]
41+
}
42+
}
43+
```
44+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Filter_With_Aliased_Filtering
2+
3+
## SQL
4+
5+
```text
6+
.param set @keys '[1]'
7+
.param set @p_startswith 'Product%'
8+
9+
SELECT "p"."Id", "p"."AvailableStock", "p"."BrandId", "p"."Description", "p"."ImageFileName", "p"."MaxStockThreshold", "p"."Name", "p"."OnReorder", "p"."Price", "p"."RestockThreshold", "p"."TypeId"
10+
FROM "Products" AS "p"
11+
WHERE "p"."BrandId" IN (
12+
SELECT "k"."value"
13+
FROM json_each(@keys) AS "k"
14+
) AND "p"."Name" LIKE @p_startswith ESCAPE '\'
15+
.param set @keys '[1]'
16+
.param set @p 'Product 0-0'
17+
18+
SELECT "p"."Id", "p"."AvailableStock", "p"."BrandId", "p"."Description", "p"."ImageFileName", "p"."MaxStockThreshold", "p"."Name", "p"."OnReorder", "p"."Price", "p"."RestockThreshold", "p"."TypeId"
19+
FROM "Products" AS "p"
20+
WHERE "p"."BrandId" IN (
21+
SELECT "k"."value"
22+
FROM json_each(@keys) AS "k"
23+
) AND "p"."Name" = @p
24+
```
25+
26+
## Result
27+
28+
```json
29+
{
30+
"data": {
31+
"a": [
32+
{
33+
"name": "Product 0-0"
34+
}
35+
],
36+
"b": [
37+
{
38+
"name": "Product 0-0"
39+
}
40+
]
41+
}
42+
}
43+
```
44+

0 commit comments

Comments
 (0)