I have an Django application with graphql endpoint. I need the ability to filter objects at once by several values of a certain field.
I have the following graphene Scheme:
class ChannelFilter(FilterSet):
type = MultipleChoiceFilter(choices=Channel.TYPES)
class Meta:
model = Channel
fields = ['type']
class ChannelNode(DjangoObjectType):
class Meta:
model = Channel
filter_fields = ['type']
interfaces = (relay.Node,)
class Query(graphene.ObjectType):
channels = DjangoFilterConnectionField(
ChannelNode, filterset_class=ChannelFilter
)
schema = graphene.Schema(query=Query)
Then i tried the following graphql queries to filter my objects:
query {
channels(type: "BOT") {
edges {
node {
id
}
}
}
}
As a result, the following error:
{
"errors": [
{
"message": "['{\"type\": [{\"message\": \"Enter a list of values.\", \"code\": \"invalid_list\"}]}']",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"channels"
]
}
],
"data": {
"channels": null
}
}
query {
channels(type: ["BOT"]) {
edges {
node {
id
}
}
}
}
As a result, the following error:
{
"errors": [
{
"message": "Argument \"type\" has invalid value [\"BOT\"].\nExpected type \"String\", found [\"BOT\"].",
"locations": [
{
"line": 2,
"column": 18
}
]
}
]
}
How to use MultipleChoiceFilter correctly? Thanks