Skip to content

Example of custom filter function for a Node Filterset  #1

Closed
@BossGrand

Description

@BossGrand

Awesome work guys really love this project!

I'm trying to do something that hasn't been documented yet and was hoping I could ask for some insight.

I have a simple node class that has a filterset for it with a custom filter function

class BuildingNode(DjangoObjectType):
    class Meta:
        interfaces = (Node, )
        model = Buildings

 class BuildingFilter(django_filters.FilterSet):
     full_address = django_filters.MethodFilter()

    def filter_full_address(self, queryset, value):
        if value:
               return querset.filter(#special_filter_case)
        return queryset

    class Meta:
         model = Buildings
         fields = {
            'address__route': ['exact', 'icontains'],
         } 

Everything filters fine on http://localhost:8000/graphiql

But on my frontend when I filter by my custom function I get warnings that look like this

Attempted to add noncontiguous index to GraphQLSegment: 12 to (0, 10)
Attempted to add noncontiguous index to GraphQLSegment: 13 to (0, 10)
Attempted to add an ID already in GraphQLSegment: client:client:-18995767902:QnVpbGRpbmdOb2RlOjMzNjkxMGFlLTY5YzQtNDU5My1iMjliLTZiNjQ5NjY0MjQyNg==

But when I filter by address__route these errors never appear.

I looked through django_graphene and couldn't find any clues on what I need to do to resolve these warnings. I'm guessing I need to wrap my queryset with something.

It would be awesome to see how to do this in the cookbook example!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions