Skip to content

Commit

Permalink
Merge pull request #599 from populationgenomics/dev
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
illusional authored Nov 1, 2023
2 parents 37618f1 + 85b0a63 commit f222398
Show file tree
Hide file tree
Showing 11 changed files with 457 additions and 510 deletions.
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

0 comments on commit f222398

Please sign in to comment.