Skip to content

Commit

Permalink
ListQueryObjectType should be filtered from the database (#16037)
Browse files Browse the repository at this point in the history
Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com>
  • Loading branch information
hyzx86 and hishamco committed May 13, 2024
1 parent abca66c commit 402d746
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
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 @@ public ListQueryObjectType(IStringLocalizer<ListQueryObjectType> S)
.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

0 comments on commit 402d746

Please sign in to comment.