Reputation: 10379
I'm wondering what the cleanest way to integrate a Graphene DjangoFilterConnectionField custom input argument into the default queryset is?
I'm iterating on the following Graphene Query class whose custom input attribute attempts to integrate the PgVector CosineDistance function:
class Query(graphene.ObjectType):
all_the_small_things = DjangoFilterConnectionField(
VectorNode,
embedding=graphene.List(graphene.Float),
)
def resolve_all_the_small_things(
root,
info,
**kwargs,
):
from pgvector.django import CosineDistance
annotations = {}
if kwargs.get("embedding"):
annotations["embedding"] = CosineDistance(
"embedding", kwargs.pop("embedding")
)
if annotations:
# How best to integrate this into the existing behavior?
# VectorNode.objects.annotate(**annotations)
# now use filter functionality provided by
# the default resolver.
I would like to augment the default query behavior (i.e. filtering) if the custom input is provided and use the default behavior as-is if it isn't. Do I need to implement my own queryset and/or filterset? Is there a way to reflect/modify the default behavior using the function arguments?
Note: I think the long term answer to this is to add support for PG Vector columns to Graphene and/or creating a django-filters filter subclass but I really need to understand how this all comes together before seriously thinking about how to approach any of that upstream.
Upvotes: 1
Views: 204