This repository was archived by the owner on Jul 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 47
Optimise manually prefetched field #244
Copy link
Copy link
Open
Description
In this comment you say that we should be able to optimise the queryset of a manually prefetched field using optimize, however this does not appear to work.
The following code in the demo directory shows that the only optimisation is not applied to my_issues:
@gql.django.type(Milestone, filters=MilestoneFilter, order=MilestoneOrder)
class MilestoneType(relay.Node):
name: gql.auto
due_date: gql.auto
project: ProjectType
issues: List["IssueType"]
@gql.django.field(
prefetch_related=[
lambda info: Prefetch(
"issues",
queryset=optimize(
Issue.objects.filter(
Exists(
Assignee.objects.filter(
issue=OuterRef("pk"),
user_id=info.context.request.user.id,
),
),
),
info,
),
to_attr="_my_issues",
),
],
)
def my_issues(self) -> List["IssueType"]:
return self._my_issues # type: ignore
@gql.django.field
async def async_field(self, value: str) -> str:
await asyncio.sleep(0)
return f"value: {value}"
Is it possible to use optimize in this way?
Thanks for the library!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels