From 8bb55ed79daae2c51e448de2730dac5c46709f22 Mon Sep 17 00:00:00 2001 From: momamene Date: Tue, 13 Dec 2016 13:23:08 +0000 Subject: [PATCH 1/7] Get name of reverse_fields from model.__dict__ --- graphene_django/types.py | 3 +-- graphene_django/utils.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/graphene_django/types.py b/graphene_django/types.py index 8174f05..76622f7 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -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 diff --git a/graphene_django/utils.py b/graphene_django/utils.py index a58db3e..7b4cd21 100644 --- a/graphene_django/utils.py +++ b/graphene_django/utils.py @@ -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 From 45542b6a93fb411db0f46494bc18003ab962fdd7 Mon Sep 17 00:00:00 2001 From: momamene Date: Wed, 14 Dec 2016 12:13:11 +0000 Subject: [PATCH 2/7] Remove meaningless guard --- graphene_django/types.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/graphene_django/types.py b/graphene_django/types.py index 76622f7..b6e4b5e 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -33,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 From 46048cd21844366e3c0b2b58e45a2fe135ae0b9a Mon Sep 17 00:00:00 2001 From: Sam Parkinson Date: Sat, 11 Mar 2017 07:40:04 +1100 Subject: [PATCH 3/7] Add tests for DjangoObjectType only/exclude_fields --- graphene_django/tests/test_types.py | 43 +++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/graphene_django/tests/test_types.py b/graphene_django/tests/test_types.py index c617fe4..0ae12c0 100644 --- a/graphene_django/tests/test_types.py +++ b/graphene_django/tests/test_types.py @@ -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 From 81ef78ad585b0fc63dbff6ea7581a6d39734c397 Mon Sep 17 00:00:00 2001 From: Ed Morley Date: Wed, 22 Mar 2017 01:59:52 +0000 Subject: [PATCH 4/7] Remove django_graphiql from cookbook requirements.txt. The package is not required since support for graphiql is now built-in. Fixes #135. --- examples/cookbook-plain/requirements.txt | 1 - examples/cookbook/requirements.txt | 1 - 2 files changed, 2 deletions(-) diff --git a/examples/cookbook-plain/requirements.txt b/examples/cookbook-plain/requirements.txt index 6931cf4..a693bd1 100644 --- a/examples/cookbook-plain/requirements.txt +++ b/examples/cookbook-plain/requirements.txt @@ -1,5 +1,4 @@ graphene graphene-django -django_graphiql graphql-core django==1.9 diff --git a/examples/cookbook/requirements.txt b/examples/cookbook/requirements.txt index 78754fd..66fa629 100644 --- a/examples/cookbook/requirements.txt +++ b/examples/cookbook/requirements.txt @@ -1,6 +1,5 @@ graphene graphene-django -django_graphiql graphql-core django==1.9 django-filter==0.11.0 From b80426e7f1bd7eb2e8df49806ba1363b601c1dd4 Mon Sep 17 00:00:00 2001 From: Kuan Date: Tue, 11 Apr 2017 09:07:28 -0700 Subject: [PATCH 5/7] Add hyperlink on documentation in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e3927a8..32ebe92 100644 --- a/README.md +++ b/README.md @@ -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: From 739d7997f3395d63973ef6ef540e0f34b68efbbb Mon Sep 17 00:00:00 2001 From: Kuan Date: Tue, 11 Apr 2017 09:09:08 -0700 Subject: [PATCH 6/7] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 21b222b..934bef7 100644 --- a/README.rst +++ b/README.rst @@ -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 `__ is generated using the excellent `Sphinx `__ and a custom theme. The documentation dependencies are installed by running: From 6fff012d088ac3bb80c88d68e70203f694d826c5 Mon Sep 17 00:00:00 2001 From: Kuan Date: Tue, 11 Apr 2017 09:10:01 -0700 Subject: [PATCH 7/7] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 32ebe92..c3f7341 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,7 @@ py.test graphene_django --cov=graphene_django # Use -v -s for verbose mode ### Documentation -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](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: