-
Notifications
You must be signed in to change notification settings - Fork 766
-
I have Appeal
and Company
model. Each Appeal
has a foreign key to Company
and some fields witch able for filtering.
Example models
class Company(models.Model): pass class Appeal(models.Model): status = models.CharField(max_length=128) company = models.ForeignKey(Company, on_delete=models.SET_NULL)
Example DjangoObjectType
class AppealType(DjangoObjectType): class Meta: model = models.Appeal fields = "__all__" filter_fields = { "status ": ["exact", "in"], } interfaces = (relay.Node,) class CompanyType(DjangoObjectType): class Meta: model = models.Company fields = "__all__" interfaces = (relay.Node,)
Query
class Query(graphene.ObjectType): # Relay node node = relay.Node.Field() appeals = DjangoFilterConnectionField(fields.AppealType) companies = DjangoFilterConnectionField(fields.CompanyType)
I want to write query which returns only objects with appeals which satisfy a condition
Example query
query Companies { companies { edges { cursor node { id appeals(status_In: ["in progress"]) { edges { cursor node { id status } } } } } } }
Now this query returns all companies and some of them have empty appeals. I want to exclude such companies from response. How to do it?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
@heckad
I think that you will need to create this condition in companies resolve.
companies = DjangoFilterConnectionField(fields.CompanyType) def resolve_companies(self, args): with_appeal_status = args.get('with_appeal_status') companies_with_approved_appeals = Company.objects.annotate( num_approved_appeals=Count('appeal', filter=Q(appeal__status__in=with_appeal_status)) ).filter(num_approved_appeals__gt=0) return companies_with_approved_appeals
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment