From 4e5acd47025043764ad113cc4613db3f80c050bd Mon Sep 17 00:00:00 2001 From: Firas Kafri <3097061+firaskafri@users.noreply.github.com> Date: Wed, 24 May 2023 16:13:23 +0300 Subject: [PATCH 01/10] Fix linting issues (#1412) --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index abf605991..542630e29 100644 --- a/setup.py +++ b/setup.py @@ -38,7 +38,7 @@ version=version, description="Graphene Django integration", long_description=open("README.md").read(), - long_description_content_type='text/markdown', + long_description_content_type="text/markdown", url="https://github.com/graphql-python/graphene-django", author="Syrus Akbary", author_email="me@syrusakbary.com", From 63fd98393f5ec725fde28d5de470245910ba0be7 Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Sat, 27 May 2023 21:26:52 +0800 Subject: [PATCH 02/10] Set pypi GH action to latest v1 (#1415) --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 139c6f683..5d5ae2724 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -20,7 +20,7 @@ jobs: pip install wheel python setup.py sdist bdist_wheel - name: Publish a Python distribution to PyPI - uses: pypa/gh-action-pypi-publish@v1.8.6 + uses: pypa/gh-action-pypi-publish@release/v1 with: user: __token__ password: ${{ secrets.pypi_password }} From 38709d83967bba6f19d6f0d6888b8b4f1cf2f720 Mon Sep 17 00:00:00 2001 From: Kien Dang Date: Sat, 27 May 2023 21:53:22 +0800 Subject: [PATCH 03/10] Correct schema write test (#1416) .called_once() just returns a Mock, so assert .called_once() always passes. We want .assert_called_once(). --- graphene_django/tests/test_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphene_django/tests/test_command.py b/graphene_django/tests/test_command.py index a281abbd2..f7325d569 100644 --- a/graphene_django/tests/test_command.py +++ b/graphene_django/tests/test_command.py @@ -46,7 +46,7 @@ class Query(ObjectType): open_mock.assert_called_once() handle = open_mock() - assert handle.write.called_once() + handle.write.assert_called_once() schema_output = handle.write.call_args[0][0] assert schema_output == dedent( From 520ddeabf69d40378992b2f90cf9b824730025fb Mon Sep 17 00:00:00 2001 From: Steven DeMartini <1647130+sjdemartini@users.noreply.github.com> Date: Fri, 2 Jun 2023 01:48:53 -0700 Subject: [PATCH 04/10] Fix graphiql explorer styles by including official CSS, and update local example app for testing (#1418) * Add venv and .venv to gitignore since common venv paths * Update cookbook-plain app requirements and local-dev notes This also adds the DEFAULT_AUTO_FIELD to the app's Django settings to resolve this warning when running `migrate`: ``` ingredients.Category: (models.W042) Auto-created primary key used when not defining a primary key type, by default 'django.db.models.AutoField'. HINT: Configure the DEFAULT_AUTO_FIELD setting or the IngredientsConfig.default_auto_field attribute to point to a subclass of AutoField, e.g. 'django.db.models.BigAutoField'. ``` * Fix #1417 graphiql explorer styles by including official CSS Like in the official graphiql-plugin-explorer example here https://github.com/graphql/graphiql/blob/619864691941c46cc0b0848e8713028e20212c36/packages/graphiql-plugin-explorer/examples/index.html#L26-L29 Resolves https://github.com/graphql-python/graphene-django/issues/1417 * Update GraphiQL version --------- Co-authored-by: Steven DeMartini Co-authored-by: Kien Dang --- .gitignore | 2 ++ examples/cookbook-plain/README.md | 9 +++++++++ examples/cookbook-plain/cookbook/settings.py | 16 +++++++++------- examples/cookbook-plain/requirements.txt | 7 +++---- graphene_django/templates/graphene/graphiql.html | 4 ++++ graphene_django/views.py | 11 +++++++---- 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index ff6bd968c..5cfaf0064 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ __pycache__/ # Distribution / packaging .Python env/ +venv/ +.venv/ build/ develop-eggs/ dist/ diff --git a/examples/cookbook-plain/README.md b/examples/cookbook-plain/README.md index dcd242087..b120b7895 100644 --- a/examples/cookbook-plain/README.md +++ b/examples/cookbook-plain/README.md @@ -62,3 +62,12 @@ Now head on over to and run some queries! (See the [Graphene-Django Tutorial](http://docs.graphene-python.org/projects/django/en/latest/tutorial-plain/#testing-our-graphql-schema) for some example queries) + +Testing local graphene-django changes +------------------------------------- + +In `requirements.txt`, replace the entire `graphene-django=...` line with the following (so that we install the local version instead of the one from PyPI): + +``` +../../ # graphene-django +``` diff --git a/examples/cookbook-plain/cookbook/settings.py b/examples/cookbook-plain/cookbook/settings.py index 7eb9d5690..f07f6f6d4 100644 --- a/examples/cookbook-plain/cookbook/settings.py +++ b/examples/cookbook-plain/cookbook/settings.py @@ -5,10 +5,10 @@ Generated by 'django-admin startproject' using Django 1.9. For more information on this file, see -https://docs.djangoproject.com/en/1.9/topics/settings/ +https://docs.djangoproject.com/en/3.2/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.9/ref/settings/ +https://docs.djangoproject.com/en/3.2/ref/settings/ """ import os @@ -18,7 +18,7 @@ # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = "_$=$%eqxk$8ss4n7mtgarw^5$8^d5+c83!vwatr@i_81myb=e4" @@ -81,7 +81,7 @@ # Database -# https://docs.djangoproject.com/en/1.9/ref/settings/#databases +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases DATABASES = { "default": { @@ -90,9 +90,11 @@ } } +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field +DEFAULT_AUTO_FIELD = "django.db.models.AutoField" # Password validation -# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [ { @@ -105,7 +107,7 @@ # Internationalization -# https://docs.djangoproject.com/en/1.9/topics/i18n/ +# https://docs.djangoproject.com/en/3.2/topics/i18n/ LANGUAGE_CODE = "en-us" @@ -119,6 +121,6 @@ # Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.9/howto/static-files/ +# https://docs.djangoproject.com/en/3.2/howto/static-files/ STATIC_URL = "/static/" diff --git a/examples/cookbook-plain/requirements.txt b/examples/cookbook-plain/requirements.txt index 85a896390..6e02745de 100644 --- a/examples/cookbook-plain/requirements.txt +++ b/examples/cookbook-plain/requirements.txt @@ -1,4 +1,3 @@ -graphene>=2.1,<3 -graphene-django>=2.1,<3 -graphql-core>=2.1,<3 -django==3.1.14 +django~=3.2 +graphene +graphene-django>=3.1 diff --git a/graphene_django/templates/graphene/graphiql.html b/graphene_django/templates/graphene/graphiql.html index ddff8fc8e..52421e868 100644 --- a/graphene_django/templates/graphene/graphiql.html +++ b/graphene_django/templates/graphene/graphiql.html @@ -21,6 +21,10 @@ integrity="{{graphiql_css_sri}}" rel="stylesheet" crossorigin="anonymous" /> + diff --git a/graphene_django/views.py b/graphene_django/views.py index 377b75d99..3fb87d410 100644 --- a/graphene_django/views.py +++ b/graphene_django/views.py @@ -66,18 +66,21 @@ class GraphQLView(View): react_dom_sri = "sha256-nbMykgB6tsOFJ7OdVmPpdqMFVk4ZsqWocT6issAPUF0=" # The GraphiQL React app. - graphiql_version = "2.4.1" # "1.0.3" - graphiql_sri = "sha256-s+f7CFAPSUIygFnRC2nfoiEKd3liCUy+snSdYFAoLUc=" # "sha256-VR4buIDY9ZXSyCNFHFNik6uSe0MhigCzgN4u7moCOTk=" - graphiql_css_sri = "sha256-88yn8FJMyGboGs4Bj+Pbb3kWOWXo7jmb+XCRHE+282k=" # "sha256-LwqxjyZgqXDYbpxQJ5zLQeNcf7WVNSJ+r8yp2rnWE/E=" + graphiql_version = "2.4.7" + graphiql_sri = "sha256-n/LKaELupC1H/PU6joz+ybeRJHT2xCdekEt6OYMOOZU=" + graphiql_css_sri = "sha256-OsbM+LQHcnFHi0iH7AUKueZvDcEBoy/z4hJ7jx1cpsM=" # The websocket transport library for subscriptions. - subscriptions_transport_ws_version = "5.12.1" + subscriptions_transport_ws_version = "5.13.1" subscriptions_transport_ws_sri = ( "sha256-EZhvg6ANJrBsgLvLAa0uuHNLepLJVCFYS+xlb5U/bqw=" ) graphiql_plugin_explorer_version = "0.1.15" graphiql_plugin_explorer_sri = "sha256-3hUuhBXdXlfCj6RTeEkJFtEh/kUG+TCDASFpFPLrzvE=" + graphiql_plugin_explorer_css_sri = ( + "sha256-fA0LPUlukMNR6L4SPSeFqDTYav8QdWjQ2nr559Zln1U=" + ) schema = None graphiql = False From 893439390936d1915d542ba631181dd4556058f0 Mon Sep 17 00:00:00 2001 From: Sezgin ACER Date: Tue, 6 Jun 2023 09:20:32 +0300 Subject: [PATCH 05/10] Add check for `serializers.HiddenField` on `fields_for_serializer` function (#1419) * Add check for `serializers.HiddenField` on fields_for_serializer function * Add pre-commit changes --- graphene_django/rest_framework/mutation.py | 3 +++ .../rest_framework/tests/test_mutation.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/graphene_django/rest_framework/mutation.py b/graphene_django/rest_framework/mutation.py index 4062a4423..b7393dad0 100644 --- a/graphene_django/rest_framework/mutation.py +++ b/graphene_django/rest_framework/mutation.py @@ -39,6 +39,9 @@ def fields_for_serializer( field.read_only and is_input and lookup_field != name, # don't show read_only fields in Input + isinstance( + field, serializers.HiddenField + ), # don't show hidden fields in Input ] ) diff --git a/graphene_django/rest_framework/tests/test_mutation.py b/graphene_django/rest_framework/tests/test_mutation.py index 5de823773..91d99f02c 100644 --- a/graphene_django/rest_framework/tests/test_mutation.py +++ b/graphene_django/rest_framework/tests/test_mutation.py @@ -164,6 +164,21 @@ class Meta: ), "'cool_name' is read_only field and shouldn't be on arguments" +def test_hidden_fields(): + class SerializerWithHiddenField(serializers.Serializer): + cool_name = serializers.CharField() + user = serializers.HiddenField(default=serializers.CurrentUserDefault()) + + class MyMutation(SerializerMutation): + class Meta: + serializer_class = SerializerWithHiddenField + + assert "cool_name" in MyMutation.Input._meta.fields + assert ( + "user" not in MyMutation.Input._meta.fields + ), "'user' is hidden field and shouldn't be on arguments" + + def test_nested_model(): class MyFakeModelGrapheneType(DjangoObjectType): class Meta: From c925a32dc3b9d0633e3f65943d2e94e1f2cc2e39 Mon Sep 17 00:00:00 2001 From: Dulmandakh Date: Wed, 7 Jun 2023 21:52:40 +0800 Subject: [PATCH 06/10] CI: add Django 4.2 (#1420) * CI: add Django 4.2 * fix tox --- .github/workflows/tests.yml | 4 +++- tox.ini | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2c5b7550c..c96bc4c2a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,13 +8,15 @@ jobs: strategy: max-parallel: 4 matrix: - django: ["3.2", "4.0", "4.1"] + django: ["3.2", "4.0", "4.1", "4.2"] python-version: ["3.8", "3.9", "3.10"] include: - django: "3.2" python-version: "3.7" - django: "4.1" python-version: "3.11" + - django: "4.2" + python-version: "3.11" steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/tox.ini b/tox.ini index e186f30ef..90110e17d 100644 --- a/tox.ini +++ b/tox.ini @@ -18,6 +18,7 @@ DJANGO = 3.2: django32 4.0: django40 4.1: django41 + 4.2: django42 main: djangomain [testenv] @@ -32,6 +33,7 @@ deps = django32: Django>=3.2,<4.0 django40: Django>=4.0,<4.1 django41: Django>=4.1,<4.2 + django42: Django>=4.2,<4.3 djangomain: https://github.com/django/django/archive/main.zip commands = {posargs:py.test --cov=graphene_django graphene_django examples} From 8fa8aea3c01d1f27babdfe0ff3288e515f56fdb1 Mon Sep 17 00:00:00 2001 From: Dulmandakh Date: Wed, 7 Jun 2023 22:36:29 +0800 Subject: [PATCH 07/10] remove JSONField compat (#1421) * remove JSONFIeld compat * fix black --- graphene_django/compat.py | 11 +---------- graphene_django/converter.py | 7 +++---- graphene_django/tests/test_converter.py | 12 ------------ graphene_django/tests/test_query.py | 3 +-- 4 files changed, 5 insertions(+), 28 deletions(-) diff --git a/graphene_django/compat.py b/graphene_django/compat.py index b0e475357..8fccdb01c 100644 --- a/graphene_django/compat.py +++ b/graphene_django/compat.py @@ -10,16 +10,7 @@ def __init__(self, *args, **kwargs): IntegerRangeField, ArrayField, HStoreField, - JSONField as PGJSONField, RangeField, ) except ImportError: - IntegerRangeField, ArrayField, HStoreField, PGJSONField, RangeField = ( - MissingType, - ) * 5 - -try: - # JSONField is only available from Django 3.1 - from django.db.models import JSONField -except ImportError: - JSONField = MissingType + IntegerRangeField, ArrayField, HStoreField, RangeField = (MissingType,) * 5 diff --git a/graphene_django/converter.py b/graphene_django/converter.py index 375d68312..a43cff76a 100644 --- a/graphene_django/converter.py +++ b/graphene_django/converter.py @@ -35,7 +35,7 @@ from graphql import assert_valid_name as assert_name from graphql.pyutils import register_description -from .compat import ArrayField, HStoreField, JSONField, PGJSONField, RangeField +from .compat import ArrayField, HStoreField, RangeField from .fields import DjangoListField, DjangoConnectionField from .settings import graphene_settings from .utils.str_converters import to_const @@ -346,9 +346,8 @@ def convert_postgres_array_to_list(field, registry=None): @convert_django_field.register(HStoreField) -@convert_django_field.register(PGJSONField) -@convert_django_field.register(JSONField) -def convert_pg_and_json_field_to_string(field, registry=None): +@convert_django_field.register(models.JSONField) +def convert_json_field_to_string(field, registry=None): return JSONString( description=get_django_field_description(field), required=not field.null ) diff --git a/graphene_django/tests/test_converter.py b/graphene_django/tests/test_converter.py index 4996505a9..7f4e350ca 100644 --- a/graphene_django/tests/test_converter.py +++ b/graphene_django/tests/test_converter.py @@ -15,8 +15,6 @@ from ..compat import ( ArrayField, HStoreField, - JSONField, - PGJSONField, MissingType, RangeField, ) @@ -372,16 +370,6 @@ def test_should_postgres_hstore_convert_string(): assert_conversion(HStoreField, JSONString) -@pytest.mark.skipif(PGJSONField is MissingType, reason="PGJSONField should exist") -def test_should_postgres_json_convert_string(): - assert_conversion(PGJSONField, JSONString) - - -@pytest.mark.skipif(JSONField is MissingType, reason="JSONField should exist") -def test_should_json_convert_string(): - assert_conversion(JSONField, JSONString) - - @pytest.mark.skipif(RangeField is MissingType, reason="RangeField should exist") def test_should_postgres_range_convert_list(): from django.contrib.postgres.fields import IntegerRangeField diff --git a/graphene_django/tests/test_query.py b/graphene_django/tests/test_query.py index 383ff2e33..68bdc7d94 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -119,13 +119,12 @@ def test_should_query_postgres_fields(): from django.contrib.postgres.fields import ( IntegerRangeField, ArrayField, - JSONField, HStoreField, ) class Event(models.Model): ages = IntegerRangeField(help_text="The age ranges") - data = JSONField(help_text="Data") + data = models.JSONField(help_text="Data") store = HStoreField() tags = ArrayField(models.CharField(max_length=50)) From 3e7a16af73311bb5ce998825250e4f35534ebfca Mon Sep 17 00:00:00 2001 From: Dulmandakh Date: Wed, 7 Jun 2023 22:36:51 +0800 Subject: [PATCH 08/10] CI: remove Django 4.0 (#1422) * CI: remove Django 4.0 * fix tags --- .github/workflows/tests.yml | 2 +- setup.py | 2 +- tox.ini | 6 ++---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c96bc4c2a..dfc5194ae 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,7 +8,7 @@ jobs: strategy: max-parallel: 4 matrix: - django: ["3.2", "4.0", "4.1", "4.2"] + django: ["3.2", "4.1", "4.2"] python-version: ["3.8", "3.9", "3.10"] include: - django: "3.2" diff --git a/setup.py b/setup.py index 542630e29..87842bb5e 100644 --- a/setup.py +++ b/setup.py @@ -56,8 +56,8 @@ "Programming Language :: Python :: Implementation :: PyPy", "Framework :: Django", "Framework :: Django :: 3.2", - "Framework :: Django :: 4.0", "Framework :: Django :: 4.1", + "Framework :: Django :: 4.2", ], keywords="api graphql protocol rest relay graphene", packages=find_packages(exclude=["tests", "examples", "examples.*"]), diff --git a/tox.ini b/tox.ini index 90110e17d..9739b1c16 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,8 @@ [tox] envlist = py{37,38,39,310}-django32, - py{38,39,310}-django{40,41,main}, - py311-django{41,main} + py{38,39,310}-django{41,42,main}, + py311-django{41,42,main} pre-commit [gh-actions] @@ -16,7 +16,6 @@ python = [gh-actions:env] DJANGO = 3.2: django32 - 4.0: django40 4.1: django41 4.2: django42 main: djangomain @@ -31,7 +30,6 @@ deps = -e.[test] psycopg2-binary django32: Django>=3.2,<4.0 - django40: Django>=4.0,<4.1 django41: Django>=4.1,<4.2 django42: Django>=4.2,<4.3 djangomain: https://github.com/django/django/archive/main.zip From 2358bd30a452859c50b6bdacdc27ae518716153b Mon Sep 17 00:00:00 2001 From: Steven DeMartini <1647130+sjdemartini@users.noreply.github.com> Date: Wed, 7 Jun 2023 10:06:37 -0700 Subject: [PATCH 09/10] Update compat.py MissingType results after PGJSONField removal (#1423) As mentioned in https://github.com/graphql-python/graphene-django/pull/1421/files#r1221711648 --- graphene_django/compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphene_django/compat.py b/graphene_django/compat.py index 8fccdb01c..2fcecf6f7 100644 --- a/graphene_django/compat.py +++ b/graphene_django/compat.py @@ -13,4 +13,4 @@ def __init__(self, *args, **kwargs): RangeField, ) except ImportError: - IntegerRangeField, ArrayField, HStoreField, RangeField = (MissingType,) * 5 + IntegerRangeField, ArrayField, HStoreField, RangeField = (MissingType,) * 4 From e950164c8ee2a9babf54a0c2d3da27194d7cfddc Mon Sep 17 00:00:00 2001 From: Firas Kafri <3097061+firaskafri@users.noreply.github.com> Date: Sat, 17 Jun 2023 09:29:18 +0300 Subject: [PATCH 10/10] Bump version to 3.1.2 --- graphene_django/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphene_django/__init__.py b/graphene_django/__init__.py index d4ef76dd7..dab70cec2 100644 --- a/graphene_django/__init__.py +++ b/graphene_django/__init__.py @@ -1,7 +1,7 @@ from .fields import DjangoConnectionField, DjangoListField from .types import DjangoObjectType -__version__ = "3.1.1" +__version__ = "3.1.2" __all__ = [ "__version__",