Skip to content

Commit

Permalink
Fix GraphQL contentitem-status filter (#17116)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Dec 5, 2024
1 parent 9c093eb commit 2fbdd36
Showing 1 changed file with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private async ValueTask<IEnumerable<ContentItem>> ResolveAsync(IResolveFieldCont

var query = preQuery.With<ContentItemIndex>();

query = FilterVersion(query, GetVersionOptions(context));
query = FilterVersion(query, context.GetArgument<PublicationStatusEnum>("status"));
query = FilterContentType(query, context);
query = OrderBy(query, context);

Expand Down Expand Up @@ -231,29 +231,19 @@ private static IQuery<ContentItem, ContentItemIndex> FilterContentType(IQuery<Co
return query.Where(q => q.ContentType == contentType);
}

private static VersionOptions GetVersionOptions(IResolveFieldContext context)
private static IQuery<ContentItem, ContentItemIndex> FilterVersion(IQuery<ContentItem, ContentItemIndex> query, PublicationStatusEnum status)
{
if (context.HasPopulatedArgument("status"))
if (status == PublicationStatusEnum.Published)
{
return GetVersionOption(context.GetArgument<PublicationStatusEnum>("status"));
query = query.Where(q => q.Published);
}

return VersionOptions.Published;
}

private static IQuery<ContentItem, ContentItemIndex> FilterVersion(IQuery<ContentItem, ContentItemIndex> query, VersionOptions versionOption)
{
if (versionOption.IsPublished)
{
query = query.Where(q => q.Published == true);
}
else if (versionOption.IsDraft)
else if (status == PublicationStatusEnum.Draft)
{
query = query.Where(q => q.Latest == true && q.Published == false);
query = query.Where(q => q.Latest && !q.Published);
}
else if (versionOption.IsLatest)
else if (status == PublicationStatusEnum.Latest)
{
query = query.Where(q => q.Latest == true);
query = query.Where(q => q.Latest);
}

return query;
Expand Down

0 comments on commit 2fbdd36

Please sign in to comment.