Skip to content

Commit 574ad15

Browse files
rishyym0927coderabbitai[bot]arkid15r
authored
Enhance GraphQL Endpoints to Support Distinct Filtering for Issues and Releases (#1154)
* recent release fix * Recent Release Fix * Update backend/apps/owasp/graphql/nodes/project.py Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Updated * Update code --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Arkadii Yakovets <[email protected]> Co-authored-by: Arkadii Yakovets <[email protected]>
1 parent 2a9b2f6 commit 574ad15

File tree

4 files changed

+76
-17
lines changed

4 files changed

+76
-17
lines changed
Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""OWASP issue GraphQL queries."""
1+
"""GraphQL queries for handling GitHub issues."""
22

33
import graphene
44

@@ -8,18 +8,47 @@
88

99

1010
class IssueQuery(BaseQuery):
11-
"""Issue queries."""
11+
"""GraphQL query class for retrieving GitHub issues."""
1212

1313
recent_issues = graphene.List(
1414
IssueNode,
15-
limit=graphene.Int(default_value=6),
15+
limit=graphene.Int(default_value=15),
16+
distinct=graphene.Boolean(default_value=False),
1617
login=graphene.String(required=False),
1718
)
1819

19-
def resolve_recent_issues(root, info, limit, login=None):
20-
"""Resolve recent issues."""
21-
queryset = Issue.objects.select_related("author").order_by("-created_at")
20+
def resolve_recent_issues(root, info, limit=15, distinct=False, login=None):
21+
"""Resolve recent issues with optional filtering.
22+
23+
Args:
24+
----
25+
root: The root query object.
26+
info: The GraphQL execution context.
27+
limit (int): Maximum number of issues to return.
28+
distinct (bool): Whether to return unique issues per author and repository.
29+
login (str, optional): Filter issues by a specific author's login.
30+
31+
Returns:
32+
-------
33+
Queryset containing the filtered list of issues.
34+
35+
"""
36+
queryset = Issue.objects.select_related(
37+
"author",
38+
).order_by(
39+
"-created_at",
40+
)
41+
2242
if login:
2343
queryset = queryset.filter(author__login=login)
2444

45+
if distinct:
46+
queryset = queryset.distinct(
47+
"author_id",
48+
"created_at",
49+
).order_by(
50+
"-created_at",
51+
"author_id",
52+
)
53+
2554
return queryset[:limit]
Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""OWASP release GraphQL queries."""
1+
"""GraphQL queries for handling OWASP releases."""
22

33
import graphene
44

@@ -8,14 +8,41 @@
88

99

1010
class ReleaseQuery(BaseQuery):
11-
"""Release queries."""
11+
"""GraphQL query class for retrieving recent GitHub releases."""
1212

13-
recent_releases = graphene.List(ReleaseNode, limit=graphene.Int(default_value=15))
13+
recent_releases = graphene.List(
14+
ReleaseNode,
15+
limit=graphene.Int(default_value=15),
16+
distinct=graphene.Boolean(default_value=False),
17+
)
1418

15-
def resolve_recent_releases(root, info, limit):
16-
"""Resolve recent release."""
17-
return Release.objects.filter(
19+
def resolve_recent_releases(root, info, limit=15, distinct=False):
20+
"""Resolve recent releases with optional distinct filtering.
21+
22+
Args:
23+
----
24+
root: The root query object.
25+
info: The GraphQL execution context.
26+
limit (int): Maximum number of releases to return.
27+
distinct (bool): Whether to return unique releases per author and repository.
28+
29+
Returns:
30+
-------
31+
Queryset containing the filtered list of releases.
32+
33+
"""
34+
query = Release.objects.filter(
1835
is_draft=False,
1936
is_pre_release=False,
2037
published_at__isnull=False,
21-
).order_by("-published_at")[:limit]
38+
).order_by("-published_at")
39+
40+
if distinct:
41+
query = query.distinct(
42+
"author_id",
43+
"published_at",
44+
).order_by(
45+
"-published_at",
46+
)
47+
48+
return query[:limit]

frontend/src/api/queries/homeQueries.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { gql } from '@apollo/client'
22

33
export const GET_MAIN_PAGE_DATA = gql`
4-
query GetMainPageData {
4+
query GetMainPageData($distinct: Boolean) {
55
recentProjects(limit: 5) {
66
createdAt
77
key
@@ -32,7 +32,7 @@ export const GET_MAIN_PAGE_DATA = gql`
3232
projectName
3333
projectUrl
3434
}
35-
recentIssues(limit: 5) {
35+
recentIssues(limit: 5, distinct: $distinct) {
3636
commentsCount
3737
createdAt
3838
title
@@ -43,7 +43,7 @@ export const GET_MAIN_PAGE_DATA = gql`
4343
name
4444
}
4545
}
46-
recentReleases(limit: 5) {
46+
recentReleases(limit: 5, distinct: $distinct) {
4747
author {
4848
avatarUrl
4949
login

frontend/src/pages/Home.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ import { toaster } from 'components/ui/toaster'
3535
export default function Home() {
3636
const [isLoading, setIsLoading] = useState<boolean>(true)
3737
const [data, setData] = useState<MainPageData>(null)
38-
const { data: graphQLData, error: graphQLRequestError } = useQuery(GET_MAIN_PAGE_DATA)
38+
const { data: graphQLData, error: graphQLRequestError } = useQuery(GET_MAIN_PAGE_DATA, {
39+
variables: { distinct: true },
40+
})
41+
3942
const [geoLocData, setGeoLocData] = useState<ChapterTypeAlgolia[]>([])
4043
const [modalOpenIndex, setModalOpenIndex] = useState<number | null>(null)
4144

0 commit comments

Comments
 (0)