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

Release #599

Merged
merged 1 commit into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion api/graphql/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class GraphQLFilter(Generic[T]):
eq: T | None = None
in_: list[T] | None = None
nin: list[T] | None = None
gt: T | None = None
gte: T | None = None
lt: T | None = None
lte: T | None = None

def all_values(self):
"""
Expand All @@ -26,6 +30,14 @@ def all_values(self):
v.extend(self.in_)
if self.nin:
v.extend(self.nin)
if self.gt:
v.append(self.gt)
if self.gte:
v.append(self.gte)
if self.lt:
v.append(self.lt)
if self.lte:
v.append(self.lte)

return v

Expand All @@ -37,9 +49,21 @@ def to_internal_filter(self, f: Callable[[T], Any] = None):
eq=f(self.eq) if self.eq else None,
in_=list(map(f, self.in_)) if self.in_ else None,
nin=list(map(f, self.nin)) if self.nin else None,
gt=f(self.gt) if self.gt else None,
gte=f(self.gte) if self.gte else None,
lt=f(self.lt) if self.lt else None,
lte=f(self.lte) if self.lte else None,
)

return GenericFilter(eq=self.eq, in_=self.in_, nin=self.nin)
return GenericFilter(
eq=self.eq,
in_=self.in_,
nin=self.nin,
gt=self.gt,
gte=self.gte,
lt=self.lt,
lte=self.lte,
)


GraphQLMetaFilter = strawberry.scalars.JSON
7 changes: 6 additions & 1 deletion api/graphql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Note, we silence a lot of linting here because GraphQL looks at type annotations
and defaults to decide the GraphQL schema, so it might not necessarily look correct.
"""
import datetime
from inspect import isclass

import strawberry
Expand Down Expand Up @@ -182,6 +183,7 @@ async def analyses(
status: GraphQLFilter[strawberry.enum(AnalysisStatus)] | None = None,
active: GraphQLFilter[bool] | None = None,
meta: GraphQLMetaFilter | None = None,
timestamp_completed: GraphQLFilter[datetime.datetime] | None = None,
) -> list['GraphQLAnalysis']:
connection = info.context['connection']
connection.project = root.id
Expand All @@ -194,6 +196,9 @@ async def analyses(
active=active.to_internal_filter() if active else None,
project=GenericFilter(eq=root.id),
meta=meta,
timestamp_completed=timestamp_completed.to_internal_filter()
if timestamp_completed
else None,
)
)
return [GraphQLAnalysis.from_internal(a) for a in internal_analysis]
Expand All @@ -207,7 +212,7 @@ class GraphQLAnalysis:
type: str
status: strawberry.enum(AnalysisStatus)
output: str | None
timestamp_completed: str | None = None
timestamp_completed: datetime.datetime | None = None
active: bool
meta: strawberry.scalars.JSON
author: str
Expand Down
Loading
Loading