def assert_conversion(django_field, graphene_field, *args): field = django_field(*args, help_text='Custom Help Text') graphene_type = convert_form_field(field) assert isinstance(graphene_type, graphene_field) field = graphene_type.as_field() assert field.description == 'Custom Help Text' return field
def get_filtering_args_from_filterset(filterset_class, type): """ Inspect a FilterSet and produce the arguments to pass to a Graphene Field. These arguments will be available to filter against in the GraphQL """ from graphene.contrib.django.form_converter import convert_form_field args = {} for name, filter_field in six.iteritems(filterset_class.base_filters): field_type = Argument(convert_form_field(filter_field.field)) args[name] = field_type # Also add the 'order_by' field if filterset_class._meta.order_by: args[filterset_class.order_by_field] = Argument(String()) return args
def test_should_manytoone_convert_connectionorlist(): field = forms.ModelChoiceField(Reporter.objects.all()) graphene_type = convert_form_field(field) assert isinstance(graphene_type, graphene.ID)
def test_should_multiple_choice_convert_connectionorlist(): field = forms.ModelMultipleChoiceField(Reporter.objects.all()) graphene_type = convert_form_field(field) assert isinstance(graphene_type, List) assert isinstance(graphene_type.of_type, ID)
def test_should_unknown_django_field_raise_exception(): with raises(Exception) as excinfo: convert_form_field(None) assert 'Don\'t know how to convert the Django form field' in str(excinfo.value)
def test_should_unknown_django_field_raise_exception(): with raises(Exception) as excinfo: convert_form_field(None) assert 'Don\'t know how to convert the Django form field' in str( excinfo.value)