Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Subclass DjangoFilterConnectionField #1430

Unanswered
ethagnawl asked this question in Q&A
Discussion options

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!

You must be logged in to vote

Replies: 1 comment

Comment options

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 
 )
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /