-
Notifications
You must be signed in to change notification settings - Fork 766
-
Is anyone aware of a simple way to subclass DjangoFilterConnectionField in order to provide default fields. Something like this:
class Query:
all_the_things = MyDjangoFilterConnectionField(
SomeNode,
# userId is provided by MyDjangoFilterConnectionField
# and there's no need to specify it across N Query classes
# userId=graphene.String()
)
Looking at the implementation, it seems like this would involve reaching into the internals a bit and, before proceeding down that path, I wanted to see if anyone had already come up with a simple/robust solve for what I imagine is a pretty common use case.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
Here's my first pass at doing this. It seems to be working but I'm not familiar enough with the API or making extensive enough use of any of the optional arguments to know if this breaks anything.
class MyDjangoFilterConnectionField(DjangoFilterConnectionField):
def __init__(
self,
type_,
fields=None,
order_by=None,
extra_filter_meta=None,
filterset_class=None,
*args,
**kwargs,
):
self._fields = fields
self._provided_filterset_class = filterset_class
self._filterset_class = None
self._filtering_args = None
self._extra_filter_meta = extra_filter_meta
self._base_args = None
kwargs["userId"] = graphene.String()
super().__init__(type_, *args, **kwargs)
class Query:
all_the_things = MyDjangoFilterConnectionField(
SomeNode,
# userId is provided implicitly by MyDjangoFilterConnectionField
)
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment