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

ListQueryObjectType should be filtered from the database #16037

Merged
merged 8 commits into from
May 13, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ public ListQueryObjectType(IStringLocalizer<ListQueryObjectType> S)
var session = serviceProvider.GetService<ISession>();
var accessor = serviceProvider.GetRequiredService<IDataLoaderContextAccessor>();

var dataLoader = accessor.Context.GetOrAddCollectionBatchLoader<string, ContentItem>("ContainedPublishedContentItems", x => LoadPublishedContentItemsForListAsync(x, session));
var dataLoader = accessor.Context.GetOrAddCollectionBatchLoader<string, ContentItem>("ContainedPublishedContentItems",
x => LoadPublishedContentItemsForListAsync(x, session, g.GetArgument<int>("skip"), g.GetArgument<int>("first")));

return ((await dataLoader.LoadAsync(g.Source.ContentItem.ContentItemId).GetResultAsync())
.Skip(g.GetArgument<int>("skip"))
.Take(g.GetArgument<int>("first")));
return await dataLoader.LoadAsync(g.Source.ContentItem.ContentItemId).GetResultAsync();
});
}

private static async Task<ILookup<string, ContentItem>> LoadPublishedContentItemsForListAsync(IEnumerable<string> contentItemIds, ISession session)
private static async Task<ILookup<string, ContentItem>> LoadPublishedContentItemsForListAsync(IEnumerable<string> contentItemIds, ISession session, int skip, int count)
{
if (contentItemIds is null || !contentItemIds.Any())
{
Expand All @@ -54,6 +53,8 @@ private static async Task<ILookup<string, ContentItem>> LoadPublishedContentItem
.With<ContentItemIndex>(ci => ci.Published)
.With<ContainedPartIndex>(cp => cp.ListContentItemId.IsIn(contentItemIds))
.OrderBy(o => o.Order)
.Skip(skip)
.Take(count)
.ListAsync();

return query.ToLookup(k => k.As<ContainedPart>().ListContentItemId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ContentItemsFieldType(string contentItemName, ISchema schema, IOptions<Gr
new QueryArgument<PublicationStatusGraphType> { Name = "status", Description = "publication status of the content item", ResolvedType = new PublicationStatusGraphType(), DefaultValue = PublicationStatusEnum.Published }
);

Resolver = new LockedAsyncFieldResolver<IEnumerable<ContentItem>>(Resolve);
Resolver = new LockedAsyncFieldResolver<IEnumerable<ContentItem>>(ResolveAsync);

schema.RegisterType(whereInput);
schema.RegisterType(orderByInput);
Expand All @@ -65,7 +65,7 @@ public ContentItemsFieldType(string contentItemName, ISchema schema, IOptions<Gr
_defaultNumberOfItems = settingsAccessor.Value.DefaultNumberOfResults;
}

private async ValueTask<IEnumerable<ContentItem>> Resolve(IResolveFieldContext context)
private async ValueTask<IEnumerable<ContentItem>> ResolveAsync(IResolveFieldContext context)

{
var versionOption = VersionOptions.Published;
Expand Down