While using graphene with Relay in django, there is an option to use filtering while querying the data.
class AnimalNode(DjangoObjectType):
class Meta:
model = Animal
filter_fields = ['name', 'genus', 'is_domesticated']
OR
filter_fields = {
'name': ['exact', 'icontains', 'istartswith'],
'genus': ['exact'],
'is_domesticated': ['exact'],
}
interfaces = (relay.Node, )
Is it possible to use filtering in this fashion while I'm not using relay or is it a relay-only feature? I don't see any filtering for non-relay in the graphene docs so can't really be sure how to proceed with this.
Absolutely, you can totally apply filtering to your data in Graphene-Django even if you're not using Relay. The fancy term here is filter_fields, which is a handy tool that lets you decide how you want to filter stuff when you're asking for data.
In your case, you've got this AnimalNode thing, right? Cool.
You can sort of tell it what fields you want to use for filtering, like 'name', 'genus', and 'is_domesticated'. You can even get a bit fancy and specify how you want to filter, like "exact", "icontains", or "istartswith".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With