GraphQL - AssertionError: resolved field 'attributes' with 'exact' lookup to an unrecognized field type JSONBField
Я пытаюсь запросить JSONBField в Python-Django. Но Graphql выбрасывает эту ошибку:
AssertionError: ResponseFilterSet разрешил поле 'attributes' с 'exact' поиском в нераспознанный тип поля JSONBField. Попробуйте добавить переопределение в 'Meta.filter_overrides'. См: https://django-filter.readthedocs.io/en/main/ref/filterset.html#customise-filter-generation-with-filter-overrides
Вот мой запрос в моем test.py:
attributes_to_query = {"Priority": ["low"], "Category": ["Service", "Speed"]}
response = self.query(
"""
query responses($attributes: GenericScalar){
responses(attributes: $attributes){
edges {
node {
id
name
attributes
}
}
}
}
""",
headers=self.get_auth_headers(),
variables={
"attributes": attributes_to_query,
},
)
Вот схема.py
class Response(AuthorizedObjectType):
class Meta:
model = models.Response
fields = [
"id",
"name",
"attributes",
]
filter_fields = ["id", "name"] >>>>>>> Adding "attributes" to this list causes the error mentioned above.
filter_overrides = {
models.Response: {
"filter_class": django_filters.CharFilter,
"extra": lambda f: {
"lookup_expr": "icontains",
},
},
}
interfaces = (relay.Node,)
class Query:
response = relay.Node.Field(Response)
responses = DjangoFilterConnectionField(
Response,
variables=graphene.Argument(GenericScalar),
attributes=graphene.Argument(GenericScalar),
)
def resolve_responses(self, info, **kwargs):
queryset = models.Response.objects.all()
if (attributes := kwargs.get("attributes")) is not None:
queryset = queryset.filter(
Q(attributes__icontains=attributes["Category"][0])
| Q(attributes__icontains=attributes["Category"][1])
)
queryset = queryset.filter(attributes__icontains=attributes["Priority"][0])
# TODO - Here I have the right 2 Responses, but test returns all, Why ?
print("Qset", queryset.values())
return queryset
# Значения в этом наборе запросов в порядке! Но в тестах они другие
Странно, потому что эта функция resolve_responses возвращает правильный набор запросов, который мне нужен. Но как-то по пути я что-то изменяю в своих данных, и мой запрос возвращает все объекты модели Response, а не только 2, которые я получаю с помощью функции "resolve_responses".
Поэтому я думаю, что мне нужно добавить "attributes" к filter_fields в schema.py/Response.Meta, но это приводит к ошибке.
Есть советы, как обойти это?