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

Added support for taking between both cursors in ef #7806

Merged
merged 3 commits into from
Dec 6, 2024
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 @@ -45,13 +45,13 @@ private async ValueTask<Connection> SliceAsync(
if (arguments.After is not null)
{
var cursor = CursorParser.Parse(arguments.After, keys);
query = query.Where(ExpressionHelpers.BuildWhereExpression<TEntity>(keys, cursor, forward));
query = query.Where(ExpressionHelpers.BuildWhereExpression<TEntity>(keys, cursor, true));
}

if (arguments.Before is not null)
{
var cursor = CursorParser.Parse(arguments.Before, keys);
query = query.Where(ExpressionHelpers.BuildWhereExpression<TEntity>(keys, cursor, forward));
query = query.Where(ExpressionHelpers.BuildWhereExpression<TEntity>(keys, cursor, false));
}

if (arguments.First is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,78 @@ public async Task Paging_Last_10_With_Default_Sorting_HasPreviousPage()
result.MatchMarkdownSnapshot();
}

[Fact]
public async Task Paging_Fetch_First_2_Items_Between()
{
var connectionString = CreateConnectionString();
await SeedAsync(connectionString);

var executor = await new ServiceCollection()
.AddScoped(_ => new CatalogContext(connectionString))
.AddGraphQLServer()
.AddQueryType<Query>()
.AddSorting()
.AddDbContextCursorPagingProvider()
.BuildRequestExecutorAsync();

var result = await executor.ExecuteAsync(q => q
.SetDocument(
"""
{
brands(first: 2, after:"MQ==", before:"NA==") {
nodes {
name
}
pageInfo {
hasNextPage
hasPreviousPage
endCursor
startCursor
}
}
}
""")
.SetGlobalState("printSQL", true));

result.MatchMarkdownSnapshot();
}

[Fact]
public async Task Paging_Fetch_Last_2_Items_Between()
{
var connectionString = CreateConnectionString();
await SeedAsync(connectionString);

var executor = await new ServiceCollection()
.AddScoped(_ => new CatalogContext(connectionString))
.AddGraphQLServer()
.AddQueryType<Query>()
.AddSorting()
.AddDbContextCursorPagingProvider()
.BuildRequestExecutorAsync();

var result = await executor.ExecuteAsync(q => q
.SetDocument(
"""
{
brands(last: 2, after:"OTc=", before:"MTAw") {
nodes {
name
}
pageInfo {
hasNextPage
hasPreviousPage
endCursor
startCursor
}
}
}
""")
.SetGlobalState("printSQL", true));

result.MatchMarkdownSnapshot();
}

public class Query
{
[UsePaging]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Paging_Fetch_First_2_Items_Between

```json
{
"data": {
"brands": {
"nodes": [
{
"name": "Brand1"
},
{
"name": "Brand2"
}
],
"pageInfo": {
"hasNextPage": true,
"hasPreviousPage": true,
"endCursor": "Mw==",
"startCursor": "Mg=="
}
}
},
"extensions": {
"sql": "-- @__p_0='1'\n-- @__p_1='4'\n-- @__p_2='3'\nSELECT b.\"Id\", b.\"AlwaysNull\", b.\"DisplayName\", b.\"Name\", b.\"BrandDetails_Country_Name\"\nFROM \"Brands\" AS b\nWHERE b.\"Id\" > @__p_0 AND b.\"Id\" < @__p_1\nORDER BY b.\"Id\"\nLIMIT @__p_2"
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Paging_Fetch_Last_2_Items_Between

```json
{
"data": {
"brands": {
"nodes": [
{
"name": "Brand97"
},
{
"name": "Brand98"
}
],
"pageInfo": {
"hasNextPage": true,
"hasPreviousPage": true,
"endCursor": "OTk=",
"startCursor": "OTg="
}
}
},
"extensions": {
"sql": "-- @__p_0='97'\n-- @__p_1='100'\n-- @__p_2='3'\nSELECT b.\"Id\", b.\"AlwaysNull\", b.\"DisplayName\", b.\"Name\", b.\"BrandDetails_Country_Name\"\nFROM \"Brands\" AS b\nWHERE b.\"Id\" > @__p_0 AND b.\"Id\" < @__p_1\nORDER BY b.\"Id\" DESC\nLIMIT @__p_2"
}
}
```
Loading