Pagination does not work on related lists
See original GitHub issueDescription
I have a JSON API endpoint which returns an entity that has a related list property. I have this configured so that when I visit /api/entity
it returns the top level entity without the associated values in the list. To get the related list of items the URL would be /api/entity/{entity-id}/items
.
During startup I have configured the JsonApiDotNetCore library to have a default page size of 10 items. This works fine for top level entities, restricting the response collection to (in this case) ten items.
services.AddJsonApi(
options =>
{
options.DefaultPageSize = 10;
...
I have a entity repository to configure the inclusion of items:
public class MyEntityRepository : DefaultEntityRepository<MyEntity, int>
{
public MyEntityRepository(
ILoggerFactory loggerFactory,
IJsonApiContext jsonApiContext,
IDbContextResolver contextResolver,
ResourceDefinition<MyEntity> resourceDefinition = null)
: base(loggerFactory, jsonApiContext, contextResolver, resourceDefinition)
{
}
public override IQueryable<MyEntity> Include(IQueryable<MyEntity> entities, string relationshipName)
{
if (relationshipName == "items")
{
return entities
.Include(o => o.Items);
}
return base.Include(entities, relationshipName);
}
}
But when I visit the /api/entity/{entity-id}/items
endpoint, that default pagination has not been applied. Furthermore, if I add pagination as a query parameter, the whole collection is still returned /api/entity/1/items?page[size]=10&page[number]=2.
Is pagination at this level not supported? Is it likely I have not configured something? Or is this a bug?
Environment
- JsonApiDotNetCore Version: 3.0.0
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:5 (4 by maintainers)
Top GitHub Comments
Possible related to https://github.com/json-api-dotnet/JsonApiDotNetCore/issues/627#issuecomment-557523219.
Thanks for opening this. I don’t have time to address this right now, but in case someone else wants to start working on it, I believe the missing piece here is that this:
https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/f72e8ae2247b39fbf1bf5af446b27e9420cf01f4/src/JsonApiDotNetCore/Services/EntityResourceService.cs#L112
Needs to be done inside here:
https://github.com/json-api-dotnet/JsonApiDotNetCore/blob/f72e8ae2247b39fbf1bf5af446b27e9420cf01f4/src/JsonApiDotNetCore/Services/EntityResourceService.cs#L131
We’ll have to think about how this will affect queries like
/a?include=b&page[number]=2
since we need to ensure paging is only applied to the target resource of the query and currently the code path that performs includes is shared. It looks like we may need to restructure this path a bit.