Код: Выделить всё
[GraphQLDescription("Returns a list of paginated questions")]
[UsePaging]
[UseFiltering]
[UseSorting]
public async Task GetQuestions([Service] IGetQuestionService questionService)
{
var result = await questionService.GetAllAsync(cancellationToken);
if (!result.IsSuccess)
throw GraphQlExceptionHelper.GetException(result.ErrorMessage!);
return result.Data;
}
< /code>
services.AddGraphQLServer()
.AddQueryType()
.AddType()
.AddSorting()
.AddFiltering()
.ModifyPagingOptions(opt =>
{
opt.DefaultPageSize = 20;
opt.IncludeTotalCount = true;
});
< /code>
According to the official Hot Chocolate documentation, cursor pagination should rely on unique, sequential values (e.g., Id
Код: Выделить всё
SELECT * FROM Users
WHERE Id >= %cursor
ORDER BY Id
LIMIT %limit
< /code>
This ensures better performance due to index usage.
However, in my setup, when querying a list like:
query {
questions(after: "Mg==", first: 3) {
edges {
cursor
node {
id
title
createdAt
}
}
}
}
< /code>
I get a response where cursors are Base64-encoded integers ("Mw=="
Вот пример ответа:
Код: Выделить всё
{
"edges": [
{
"cursor": "Mw==",
"node": {
"id": 6,
"title": "How to implement CQRS pattern in a .NET application?",
"createdAt": "2025-03-12T13:46:27.050Z"
}
},
{
"cursor": "NA==",
"node": {
"id": 7,
"title": "What is overfitting in AI models and how can I prevent it?",
"createdAt": "2025-04-28T09:20:10.757Z"
}
},
{
"cursor": "NQ==",
"node": {
"id": 8,
"title": "How to properly implement Dependency Injection in .NET Core?",
"createdAt": "2025-05-31T07:25:20.665Z"
}
}
]
}
< /code>
Decoding "Mw=="
Код: Выделить всё
"NA=="
Код: Выделить всё
6
Это говорит о том, что система назначает последовательные индексы, независимые от фактических значений данных.
Код: Выделить всё
SELECT q."Id", q."Body", q."CreatedAt"
FROM "Question" AS q
LIMIT @__p_1 OFFSET @__p_0
< /code>
This appears to be offset-based pagination, not cursor-based as expected. There's no WHERE
Код: Выделить всё
OFFSET
Мои вопросы:
Почему сгенерированные курсоры не соответствуют фактическому идентификатору или другим значимым полям (например. Применяется конфигурация? Создал или id ) для использования для генерации и сравнения курсора? Но результат остался прежним. Курсоры по -прежнему не отражали никакого реального поля, и сгенерированный SQL продолжал использовать Offset .
Подробнее здесь: https://stackoverflow.com/questions/796 ... on-am-i-mi