mirror of
				https://github.com/graphql-python/graphene-django.git
				synced 2025-10-31 16:07:36 +03:00 
			
		
		
		
	Merge branch 'master' into fix-filter-and-resolver
This commit is contained in:
		
						commit
						055c6e2359
					
				|  | @ -111,7 +111,7 @@ py.test graphene_django --cov=graphene_django # Use -v -s for verbose mode | |||
| 
 | ||||
| ### Documentation | ||||
| 
 | ||||
| The documentation is generated using the excellent [Sphinx](http://www.sphinx-doc.org/) and a custom theme. | ||||
| The [documentation](http://docs.graphene-python.org/projects/django/en/latest/) is generated using the excellent [Sphinx](http://www.sphinx-doc.org/) and a custom theme. | ||||
| 
 | ||||
| The documentation dependencies are installed by running: | ||||
| 
 | ||||
|  |  | |||
|  | @ -120,7 +120,7 @@ After developing, the full test suite can be evaluated by running: | |||
| Documentation | ||||
| ~~~~~~~~~~~~~ | ||||
| 
 | ||||
| The documentation is generated using the excellent | ||||
| The `documentation <http://docs.graphene-python.org/projects/django/en/latest/>`__ is generated using the excellent | ||||
| `Sphinx <http://www.sphinx-doc.org/>`__ and a custom theme. | ||||
| 
 | ||||
| The documentation dependencies are installed by running: | ||||
|  |  | |||
|  | @ -1,5 +1,4 @@ | |||
| graphene | ||||
| graphene-django | ||||
| django_graphiql | ||||
| graphql-core | ||||
| django==1.9 | ||||
|  |  | |||
|  | @ -1,6 +1,5 @@ | |||
| graphene | ||||
| graphene-django | ||||
| django_graphiql | ||||
| graphql-core | ||||
| django==1.9 | ||||
| django-filter==0.11.0 | ||||
|  |  | |||
|  | @ -3,12 +3,12 @@ from mock import patch | |||
| from graphene import Interface, ObjectType, Schema | ||||
| from graphene.relay import Node | ||||
| 
 | ||||
| from ..registry import reset_global_registry | ||||
| from .. import registry | ||||
| from ..types import DjangoObjectType | ||||
| from .models import Article as ArticleModel | ||||
| from .models import Reporter as ReporterModel | ||||
| 
 | ||||
| reset_global_registry() | ||||
| registry.reset_global_registry() | ||||
| 
 | ||||
| 
 | ||||
| class Reporter(DjangoObjectType): | ||||
|  | @ -124,3 +124,42 @@ type RootQuery { | |||
| } | ||||
| """.lstrip() | ||||
|     assert str(schema) == expected | ||||
| 
 | ||||
| 
 | ||||
| def with_local_registry(func): | ||||
|     def inner(*args, **kwargs): | ||||
|         old = registry.get_global_registry() | ||||
|         registry.reset_global_registry() | ||||
|         try: | ||||
|             retval = func(*args, **kwargs) | ||||
|         except Exception as e: | ||||
|             registry.registry = old | ||||
|             raise e | ||||
|         else: | ||||
|             registry.registry = old | ||||
|             return retval | ||||
|     return inner | ||||
| 
 | ||||
| 
 | ||||
| @with_local_registry | ||||
| def test_django_objecttype_only_fields(): | ||||
|     class Reporter(DjangoObjectType): | ||||
|         class Meta: | ||||
|             model = ReporterModel | ||||
|             only_fields = ('id', 'email', 'films') | ||||
| 
 | ||||
| 
 | ||||
|     fields = list(Reporter._meta.fields.keys()) | ||||
|     assert fields == ['id', 'email', 'films'] | ||||
| 
 | ||||
| 
 | ||||
| @with_local_registry | ||||
| def test_django_objecttype_exclude_fields(): | ||||
|     class Reporter(DjangoObjectType): | ||||
|         class Meta: | ||||
|             model = ReporterModel | ||||
|             exclude_fields = ('email') | ||||
| 
 | ||||
| 
 | ||||
|     fields = list(Reporter._meta.fields.keys()) | ||||
|     assert 'email' not in fields | ||||
|  |  | |||
|  | @ -21,8 +21,7 @@ def construct_fields(options): | |||
|     exclude_fields = options.exclude_fields | ||||
| 
 | ||||
|     fields = OrderedDict() | ||||
|     for field in _model_fields: | ||||
|         name = field.name | ||||
|     for name, field in _model_fields: | ||||
|         is_not_in_only = only_fields and name not in options.only_fields | ||||
|         is_already_created = name in options.fields | ||||
|         is_excluded = name in exclude_fields or is_already_created | ||||
|  | @ -34,8 +33,6 @@ def construct_fields(options): | |||
|             # Or when there is no back reference. | ||||
|             continue | ||||
|         converted = convert_django_field_with_choices(field, options.registry) | ||||
|         if not converted: | ||||
|             continue | ||||
|         fields[name] = converted | ||||
| 
 | ||||
|     return fields | ||||
|  |  | |||
|  | @ -30,11 +30,11 @@ def get_reverse_fields(model): | |||
|             # Hack for making it compatible with Django 1.6 | ||||
|             new_related = RelatedObject(related.parent_model, related.model, related.field) | ||||
|             new_related.name = name | ||||
|             yield new_related | ||||
|             yield (name, new_related) | ||||
|         elif isinstance(related, models.ManyToOneRel): | ||||
|             yield related | ||||
|             yield (name, related) | ||||
|         elif isinstance(related, models.ManyToManyRel) and not related.symmetrical: | ||||
|             yield related | ||||
|             yield (name, related) | ||||
| 
 | ||||
| 
 | ||||
| def maybe_queryset(value): | ||||
|  | @ -45,8 +45,13 @@ def maybe_queryset(value): | |||
| 
 | ||||
| def get_model_fields(model): | ||||
|     reverse_fields = get_reverse_fields(model) | ||||
|     all_fields = sorted(list(model._meta.fields) + | ||||
|                         list(model._meta.local_many_to_many)) | ||||
|     all_fields = [ | ||||
|         (field.name, field) | ||||
|         for field | ||||
|         in sorted(list(model._meta.fields) + | ||||
|                   list(model._meta.local_many_to_many)) | ||||
|     ] | ||||
| 
 | ||||
|     all_fields += list(reverse_fields) | ||||
| 
 | ||||
|     return all_fields | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user