-
Notifications
You must be signed in to change notification settings - Fork 766
#534 add filterset validation to DjangoFilterConnectionField #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from collections import OrderedDict | ||
from functools import partial | ||
|
||
from graphql.error import GraphQLError | ||
from graphene.types.argument import to_arguments | ||
from ..fields import DjangoConnectionField | ||
from .utils import get_filtering_args_from_filterset, get_filterset_class | ||
|
@@ -89,11 +90,22 @@ def connection_resolver( | |
**args | ||
): | ||
filter_kwargs = {k: v for k, v in args.items() if k in filtering_args} | ||
qs = filterset_class( | ||
|
||
filterset = filterset_class( | ||
data=filter_kwargs, | ||
queryset=default_manager.get_queryset(), | ||
request=info.context, | ||
).qs | ||
) | ||
|
||
if not (filterset.is_bound and filterset.form.is_valid()): | ||
exc = { | ||
str(key): [str(e.message) for e in error_list] | ||
for key, error_list in filterset.form.errors.as_data().items() | ||
} | ||
|
||
raise GraphQLError(exc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we're passing a dictionary here, but GraphQLError appears to take a One alternative would be to wrap up the a) make the code here simpler |
||
|
||
qs = filterset.qs | ||
|
||
return super(DjangoFilterConnectionField, cls).connection_resolver( | ||
resolver, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The key here is in Python/Django source casing I believe. I think we could improve the error reporting here anyway (see other comment), but if we do want to send these to the client, they should use the field names as in the API – i.e. probably
camelCase
names, although I believe this can be configured per schema, and overridden per field.