Filtering using Django Integer Choices
See original GitHub issueHey guys, I am a real noob with GraphQL, but I think I found a bug, I am trying to filter using an integer choice, below you will see the definitions:
models.py
class Event(models.Model):
KIND_XXX = 1
KIND_CHOICES = (
(KIND_XXX, "Dummy description"),
)
name = models.CharField(max_length=35)
kind = models.IntegerField(choices=KIND_CHOICES)
schema.py
class EventNode(DjangoObjectType):
class Meta:
model = Event
filter_fields = {
'name': ['exact', 'in', 'icontains', 'istartswith'],
'kind': ['exact', 'in', 'icontains', 'istartswith'],
}
interfaces = (graphene.relay.Node,)
class Query(graphene.ObjectType):
event = graphene.relay.Node.Field(EventNode)
all_events = DjangoFilterConnectionField(EventNode)
If I query using name
, name__in
, etc it works, but when I try to filter by kind__in
it says I need an Float
which is wrong.
Please note the Float there:
Result:
{
"errors": [
{
"message": "Argument \"kind_In\" has invalid value \"1\".\nExpected type \"Float\", found \"1\".",
"locations": [
{
"line": 2,
"column": 22
}
]
}
]
}
As a second help request, I found other issue (but I am not sure if I am misunderstanding something) if I query for a not existent kind
it returns the information:
Query for all records…
query{
allEvents{
edges{
node{
kind
name
}
}
}
}
Result for all records
{
"data": {
"allEvents": {
"edges": [
{
"node": {
"kind": "A_1",
"name": "Event X"
}
}
]
}
}
}
Query for not existent kind choice
query{
allEvents(kind: "2"){
edges{
node{
kind
name
}
}
}
}
Result for not existent kind choice
{
"data": {
"allEvents": {
"edges": [
{
"node": {
"kind": "A_1",
"name": "Event X"
}
}
]
}
}
}
I spent like 8 hours debugging, but I couldn’t find any solution, if you can address for a solution, I can PR the fix (in case it is really a bug…,)
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (6 by maintainers)
Top GitHub Comments
Dupe of #67
The second issue, returning all records as failure mode, may be related to this issue:
DjangoFilterConnectionField and filter_set issues.