Skip to content

Commit 6210273

Browse files
authored
Merge branch 'main' into debug-middleware-sql-bytes
2 parents a8e341b + 9a773b9 commit 6210273

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1232
-337
lines changed

.github/workflows/deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
pip install wheel
2121
python setup.py sdist bdist_wheel
2222
- name: Publish a Python distribution to PyPI
23-
uses: pypa/gh-action-pypi-publish@v1.8.6
23+
uses: pypa/gh-action-pypi-publish@release/v1
2424
with:
2525
user: __token__
2626
password: ${{ secrets.pypi_password }}

.github/workflows/lint.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Lint
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
47

58
jobs:
69
build:

.github/workflows/tests.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
name: Tests
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
47

58
jobs:
69
build:
710
runs-on: ubuntu-latest
811
strategy:
912
max-parallel: 4
1013
matrix:
11-
django: ["3.2", "4.0", "4.1"]
14+
django: ["3.2", "4.1", "4.2"]
1215
python-version: ["3.8", "3.9", "3.10"]
1316
include:
14-
- django: "3.2"
15-
python-version: "3.7"
1617
- django: "4.1"
1718
python-version: "3.11"
19+
- django: "4.2"
20+
python-version: "3.11"
1821
steps:
1922
- uses: actions/checkout@v3
2023
- name: Set up Python ${{ matrix.python-version }}
@@ -29,4 +32,3 @@ jobs:
2932
run: tox
3033
env:
3134
DJANGO: ${{ matrix.django }}
32-
TOXENV: ${{ matrix.toxenv }}

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ __pycache__/
1111
# Distribution / packaging
1212
.Python
1313
env/
14+
.env/
15+
venv/
16+
.venv/
1417
build/
1518
develop-eggs/
1619
dist/

.pre-commit-config.yaml

+5-9
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ repos:
1515
- --autofix
1616
- id: trailing-whitespace
1717
exclude: README.md
18-
- repo: https://github.com/asottile/pyupgrade
19-
rev: v3.3.2
20-
hooks:
21-
- id: pyupgrade
22-
args: [--py37-plus]
2318
- repo: https://github.com/psf/black
24-
rev: 23.3.0
19+
rev: 23.7.0
2520
hooks:
2621
- id: black
27-
- repo: https://github.com/PyCQA/flake8
28-
rev: 6.0.0
22+
- repo: https://github.com/astral-sh/ruff-pre-commit
23+
rev: v0.0.282
2924
hooks:
30-
- id: flake8
25+
- id: ruff
26+
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

.ruff.toml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
select = [
2+
"E", # pycodestyle
3+
"W", # pycodestyle
4+
"F", # pyflake
5+
"I", # isort
6+
"B", # flake8-bugbear
7+
"C4", # flake8-comprehensions
8+
"UP", # pyupgrade
9+
]
10+
11+
ignore = [
12+
"E501", # line-too-long
13+
"B017", # pytest.raises(Exception) should be considered evil
14+
"B028", # warnings.warn called without an explicit stacklevel keyword argument
15+
"B904", # check for raise statements in exception handlers that lack a from clause
16+
]
17+
18+
exclude = [
19+
"**/docs",
20+
]
21+
22+
target-version = "py38"
23+
24+
[per-file-ignores]
25+
# Ignore unused imports (F401) in these files
26+
"__init__.py" = ["F401"]
27+
"graphene_django/compat.py" = ["F401"]
28+
29+
[isort]
30+
known-first-party = ["graphene", "graphene-django"]
31+
known-local-folder = ["cookbook"]
32+
force-wrap-aliases = true
33+
combine-as-imports = true

docs/authorization.rst

+17-2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,21 @@ If you are using ``DjangoObjectType`` you can define a custom `get_queryset`.
144144
return queryset.filter(published=True)
145145
return queryset
146146
147+
.. warning::
148+
149+
Defining a custom ``get_queryset`` gives the guaranteed it will be called
150+
when resolving the ``DjangoObjectType``, even through related objects.
151+
Note that because of this, benefits from using ``select_related``
152+
in objects that define a relation to this ``DjangoObjectType`` will be canceled out.
153+
In the case of ``prefetch_related``, the benefits of the optimization will be lost only
154+
if the custom ``get_queryset`` modifies the queryset. For more information about this, refers
155+
to Django documentation about ``prefetch_related``: https://docs.djangoproject.com/en/4.2/ref/models/querysets/#prefetch-related.
156+
157+
158+
If you want to explicitly disable the execution of the custom ``get_queryset`` when resolving,
159+
you can decorate the resolver with `@graphene_django.bypass_get_queryset`. Note that this
160+
can lead to authorization leaks if you are performing authorization checks in the custom
161+
``get_queryset``.
147162

148163
Filtering ID-based Node Access
149164
------------------------------
@@ -197,8 +212,8 @@ For Django 2.2 and above:
197212
.. code:: python
198213
199214
urlpatterns = [
200-
# some other urls
201-
path('graphql/', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
215+
# some other urls
216+
path('graphql/', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
202217
]
203218
204219
.. _LoginRequiredMixin: https://docs.djangoproject.com/en/dev/topics/auth/default/#the-loginrequired-mixin

docs/introspection.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ specify the parameters in your settings.py:
5757
.. code:: python
5858
5959
GRAPHENE = {
60-
'SCHEMA': 'tutorial.quickstart.schema',
61-
'SCHEMA_OUTPUT': 'data/schema.json', # defaults to schema.json,
62-
'SCHEMA_INDENT': 2, # Defaults to None (displays all data on a single line)
60+
'SCHEMA': 'tutorial.quickstart.schema',
61+
'SCHEMA_OUTPUT': 'data/schema.json', # defaults to schema.json,
62+
'SCHEMA_INDENT': 2, # Defaults to None (displays all data on a single line)
6363
}
6464
6565

docs/tutorial-relay.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ app <https://github.com/graphql-python/graphene-django/tree/master/examples/cook
1212
A good idea is to check the following things first:
1313

1414
* `Graphene Relay documentation <http://docs.graphene-python.org/en/latest/relay/>`__
15-
* `GraphQL Relay Specification <https://facebook.github.io/relay/docs/en/graphql-server-specification.html>`__
15+
* `GraphQL Relay Specification <https://relay.dev/docs/guides/graphql-server-specification/>`__
1616

1717
Setup the Django project
1818
------------------------

examples/cookbook-plain/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,12 @@ Now head on over to
6262
and run some queries!
6363
(See the [Graphene-Django Tutorial](http://docs.graphene-python.org/projects/django/en/latest/tutorial-plain/#testing-our-graphql-schema)
6464
for some example queries)
65+
66+
Testing local graphene-django changes
67+
-------------------------------------
68+
69+
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):
70+
71+
```
72+
../../ # graphene-django
73+
```

examples/cookbook-plain/cookbook/schema.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import cookbook.ingredients.schema
2-
import cookbook.recipes.schema
31
import graphene
4-
52
from graphene_django.debug import DjangoDebug
63

4+
import cookbook.ingredients.schema
5+
import cookbook.recipes.schema
6+
77

88
class Query(
99
cookbook.ingredients.schema.Query,

examples/cookbook-plain/cookbook/settings.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
Generated by 'django-admin startproject' using Django 1.9.
66
77
For more information on this file, see
8-
https://docs.djangoproject.com/en/1.9/topics/settings/
8+
https://docs.djangoproject.com/en/3.2/topics/settings/
99
1010
For the full list of settings and their values, see
11-
https://docs.djangoproject.com/en/1.9/ref/settings/
11+
https://docs.djangoproject.com/en/3.2/ref/settings/
1212
"""
1313

1414
import os
@@ -18,7 +18,7 @@
1818

1919

2020
# Quick-start development settings - unsuitable for production
21-
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
21+
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
2222

2323
# SECURITY WARNING: keep the secret key used in production secret!
2424
SECRET_KEY = "_$=$%eqxk$8ss4n7mtgarw^5$8^d5+c83!vwatr@i_81myb=e4"
@@ -81,7 +81,7 @@
8181

8282

8383
# Database
84-
# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
84+
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
8585

8686
DATABASES = {
8787
"default": {
@@ -90,9 +90,11 @@
9090
}
9191
}
9292

93+
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
94+
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
9395

9496
# Password validation
95-
# https://docs.djangoproject.com/en/1.9/ref/settings/#auth-password-validators
97+
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
9698

9799
AUTH_PASSWORD_VALIDATORS = [
98100
{
@@ -105,7 +107,7 @@
105107

106108

107109
# Internationalization
108-
# https://docs.djangoproject.com/en/1.9/topics/i18n/
110+
# https://docs.djangoproject.com/en/3.2/topics/i18n/
109111

110112
LANGUAGE_CODE = "en-us"
111113

@@ -119,6 +121,6 @@
119121

120122

121123
# Static files (CSS, JavaScript, Images)
122-
# https://docs.djangoproject.com/en/1.9/howto/static-files/
124+
# https://docs.djangoproject.com/en/3.2/howto/static-files/
123125

124126
STATIC_URL = "/static/"

examples/cookbook-plain/cookbook/urls.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from django.urls import path
21
from django.contrib import admin
2+
from django.urls import path
33

44
from graphene_django.views import GraphQLView
55

6-
76
urlpatterns = [
87
path("admin/", admin.site.urls),
98
path("graphql/", GraphQLView.as_view(graphiql=True)),
+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
graphene>=2.1,<3
2-
graphene-django>=2.1,<3
3-
graphql-core>=2.1,<3
4-
django==3.1.14
1+
django~=3.2
2+
graphene
3+
graphene-django>=3.1

examples/cookbook/cookbook/ingredients/schema.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from cookbook.ingredients.models import Category, Ingredient
21
from graphene import Node
32
from graphene_django.filter import DjangoFilterConnectionField
43
from graphene_django.types import DjangoObjectType
54

5+
from cookbook.ingredients.models import Category, Ingredient
6+
67

78
# Graphene will automatically map the Category model's fields onto the CategoryNode.
89
# This is configured in the CategoryNode's Meta class (as you can see below)

examples/cookbook/cookbook/recipes/models.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
class Recipe(models.Model):
77
title = models.CharField(max_length=100)
88
instructions = models.TextField()
9-
__unicode__ = lambda self: self.title
9+
10+
def __unicode__(self):
11+
return self.title
1012

1113

1214
class RecipeIngredient(models.Model):

examples/cookbook/cookbook/recipes/schema.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from cookbook.recipes.models import Recipe, RecipeIngredient
21
from graphene import Node
32
from graphene_django.filter import DjangoFilterConnectionField
43
from graphene_django.types import DjangoObjectType
54

5+
from cookbook.recipes.models import Recipe, RecipeIngredient
6+
67

78
class RecipeNode(DjangoObjectType):
89
class Meta:

examples/cookbook/cookbook/schema.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import cookbook.ingredients.schema
2-
import cookbook.recipes.schema
31
import graphene
4-
52
from graphene_django.debug import DjangoDebug
63

4+
import cookbook.ingredients.schema
5+
import cookbook.recipes.schema
6+
77

88
class Query(
99
cookbook.ingredients.schema.Query,

examples/cookbook/cookbook/urls.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from graphene_django.views import GraphQLView
55

6-
76
urlpatterns = [
87
url(r"^admin/", admin.site.urls),
98
url(r"^graphql$", GraphQLView.as_view(graphiql=True)),

examples/django_test_settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import sys
21
import os
2+
import sys
33

44
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
55
sys.path.insert(0, ROOT_PATH + "/examples/")

examples/starwars/schema.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
from graphene_django import DjangoConnectionField, DjangoObjectType
44

55
from .data import create_ship, get_empire, get_faction, get_rebels, get_ship, get_ships
6-
from .models import Character as CharacterModel
7-
from .models import Faction as FactionModel
8-
from .models import Ship as ShipModel
6+
from .models import (
7+
Character as CharacterModel,
8+
Faction as FactionModel,
9+
Ship as ShipModel,
10+
)
911

1012

1113
class Ship(DjangoObjectType):

graphene_django/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
from .fields import DjangoConnectionField, DjangoListField
22
from .types import DjangoObjectType
3+
from .utils import bypass_get_queryset
34

4-
__version__ = "3.0.2"
5+
__version__ = "3.1.3"
56

67
__all__ = [
78
"__version__",
89
"DjangoObjectType",
910
"DjangoListField",
1011
"DjangoConnectionField",
12+
"bypass_get_queryset",
1113
]

0 commit comments

Comments
 (0)