Skip to content

Commit 49d897b

Browse files
authored
Merge 696b590 into cf9f590
2 parents cf9f590 + 696b590 commit 49d897b

29 files changed

+454
-416
lines changed

.travis.yml

+13-24
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ dist: xenial
55
install:
66
- pip install tox tox-travis
77

8-
script:
8+
script:
99
- tox
1010

11-
after_success:
11+
after_success:
1212
- pip install coveralls
1313
- coveralls
1414

@@ -24,24 +24,8 @@ jobs:
2424
- env: DJANGO=master
2525

2626
include:
27-
- python: 2.7
28-
env: DJANGO=1.11
29-
30-
- python: 3.5
31-
env: DJANGO=1.11
32-
- python: 3.5
33-
env: DJANGO=2.0
34-
- python: 3.5
35-
env: DJANGO=2.1
36-
- python: 3.5
37-
env: DJANGO=2.2
38-
3927
- python: 3.6
4028
env: DJANGO=1.11
41-
- python: 3.6
42-
env: DJANGO=2.0
43-
- python: 3.6
44-
env: DJANGO=2.1
4529
- python: 3.6
4630
env: DJANGO=2.2
4731
- python: 3.6
@@ -51,23 +35,28 @@ jobs:
5135

5236
- python: 3.7
5337
env: DJANGO=1.11
54-
- python: 3.7
55-
env: DJANGO=2.0
56-
- python: 3.7
57-
env: DJANGO=2.1
5838
- python: 3.7
5939
env: DJANGO=2.2
6040
- python: 3.7
6141
env: DJANGO=3.0
6242
- python: 3.7
6343
env: DJANGO=master
6444

65-
- python: 3.7
45+
- python: 3.8
46+
env: DJANGO=1.11
47+
- python: 3.8
48+
env: DJANGO=2.2
49+
- python: 3.8
50+
env: DJANGO=3.0
51+
- python: 3.8
52+
env: DJANGO=master
53+
54+
- python: 3.8
6655
env: TOXENV=black,flake8
6756

6857
- stage: deploy
6958
script: skip
70-
python: 3.7
59+
python: 3.8
7160
after_success: true
7261
deploy:
7362
provider: pypi

docs/authorization.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,4 @@ For Django 2.0 and above:
184184
path('graphql', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
185185
]
186186
187-
.. _LoginRequiredMixin: https://docs.djangoproject.com/en/1.10/topics/auth/default/#the-loginrequired-mixin
187+
.. _LoginRequiredMixin: https://docs.djangoproject.com/en/dev/topics/auth/default/#the-loginrequired-mixin

docs/conf.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@
6060
master_doc = "index"
6161

6262
# General information about the project.
63-
project = u"Graphene Django"
64-
copyright = u"Graphene 2017"
65-
author = u"Syrus Akbary"
63+
project = "Graphene Django"
64+
copyright = "Graphene 2017"
65+
author = "Syrus Akbary"
6666

6767
# The version info for the project you're documenting, acts as replacement for
6868
# |version| and |release|, also used in various other places throughout the
6969
# built documents.
7070
#
7171
# The short X.Y version.
72-
version = u"1.0"
72+
version = "1.0"
7373
# The full version, including alpha/beta/rc tags.
74-
release = u"1.0.dev"
74+
release = "1.0.dev"
7575

7676
# The language for content autogenerated by Sphinx. Refer to documentation
7777
# for a list of supported languages.
@@ -276,7 +276,7 @@
276276
# (source start file, target name, title,
277277
# author, documentclass [howto, manual, or own class]).
278278
latex_documents = [
279-
(master_doc, "Graphene.tex", u"Graphene Documentation", u"Syrus Akbary", "manual")
279+
(master_doc, "Graphene.tex", "Graphene Documentation", "Syrus Akbary", "manual")
280280
]
281281

282282
# The name of an image file (relative to this directory) to place at the top of
@@ -317,7 +317,7 @@
317317
# One entry per manual page. List of tuples
318318
# (source start file, name, description, authors, manual section).
319319
man_pages = [
320-
(master_doc, "graphene_django", u"Graphene Django Documentation", [author], 1)
320+
(master_doc, "graphene_django", "Graphene Django Documentation", [author], 1)
321321
]
322322

323323
# If true, show URL addresses after external links.
@@ -334,7 +334,7 @@
334334
(
335335
master_doc,
336336
"Graphene-Django",
337-
u"Graphene Django Documentation",
337+
"Graphene Django Documentation",
338338
author,
339339
"Graphene Django",
340340
"One line description of project.",

docs/filtering.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ Filtering
22
=========
33

44
Graphene integrates with
5-
`django-filter <https://django-filter.readthedocs.io/en/master/>`__ (2.x for
6-
Python 3 or 1.x for Python 2) to provide filtering of results. See the `usage
5+
`django-filter <https://django-filter.readthedocs.io/en/master/>`__ to provide filtering of results. See the `usage
76
documentation <https://django-filter.readthedocs.io/en/master/guide/usage.html#the-filter>`__
87
for details on the format for ``filter_fields``.
98

graphene_django/converter.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
from collections import OrderedDict
2+
from functools import singledispatch
3+
24
from django.db import models
35
from django.utils.encoding import force_str
46
from django.utils.module_loading import import_string
@@ -21,21 +23,18 @@
2123
)
2224
from graphene.types.json import JSONString
2325
from graphene.utils.str_converters import to_camel_case, to_const
24-
from graphql import assert_valid_name
26+
from graphql import assert_valid_name, GraphQLError
2527

2628
from .settings import graphene_settings
2729
from .compat import ArrayField, HStoreField, JSONField, RangeField
2830
from .fields import DjangoListField, DjangoConnectionField
29-
from .utils import import_single_dispatch
30-
31-
singledispatch = import_single_dispatch()
3231

3332

3433
def convert_choice_name(name):
3534
name = to_const(force_str(name))
3635
try:
3736
assert_valid_name(name)
38-
except AssertionError:
37+
except GraphQLError:
3938
name = "A_%s" % name
4039
return name
4140

@@ -65,7 +64,7 @@ def convert_choices_to_named_enum_with_descriptions(name, choices):
6564
class EnumWithDescriptionsType(object):
6665
@property
6766
def description(self):
68-
return named_choices_descriptions[self.name]
67+
return str(named_choices_descriptions[self.name])
6968

7069
return Enum(name, list(named_choices), type=EnumWithDescriptionsType)
7170

@@ -277,3 +276,12 @@ def convert_postgres_range_to_string(field, registry=None):
277276
if not isinstance(inner_type, (List, NonNull)):
278277
inner_type = type(inner_type)
279278
return List(inner_type, description=field.help_text, required=not field.null)
279+
280+
281+
from django.utils.functional import Promise
282+
from graphql.pyutils import register_description
283+
284+
285+
# Register Django lazy()-wrapped values as GraphQL description/help_text.
286+
# This is needed for using lazy translations, see https://github.com/graphql-python/graphql-core-next/issues/58.
287+
register_description(Promise)

graphene_django/debug/middleware.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def get_debug_promise(self):
1717
if not self.debug_promise:
1818
self.debug_promise = Promise.all(self.promises)
1919
self.promises = []
20-
return self.debug_promise.then(self.on_resolve_all_promises)
20+
return self.debug_promise.then(self.on_resolve_all_promises).get()
2121

2222
def on_resolve_all_promises(self, values):
2323
if self.promises:

graphene_django/debug/sql/tracking.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from threading import local
66
from time import time
77

8-
import six
98
from django.utils.encoding import force_str
109

1110
from .types import DjangoDebugSQL
@@ -77,7 +76,7 @@ def __init__(self, cursor, db, logger):
7776
self.logger = logger
7877

7978
def _quote_expr(self, element):
80-
if isinstance(element, six.string_types):
79+
if isinstance(element, str):
8180
return "'%s'" % force_str(element).replace("'", "''")
8281
else:
8382
return repr(element)

graphene_django/debug/tests/test_query.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Meta:
7575

7676
class Query(graphene.ObjectType):
7777
reporter = graphene.Field(ReporterType)
78-
debug = graphene.Field(DjangoDebug, name="__debug")
78+
debug = graphene.Field(DjangoDebug, name="_debug")
7979

8080
def resolve_reporter(self, info, **args):
8181
return Reporter.objects.first()
@@ -89,7 +89,7 @@ def resolve_reporter(self, info, **args):
8989
pets { edges { node { lastName } } }
9090
} } }
9191
}
92-
__debug {
92+
_debug {
9393
sql {
9494
rawSql
9595
}
@@ -117,12 +117,12 @@ def resolve_reporter(self, info, **args):
117117
)
118118
assert not result.errors
119119
query = str(Reporter.objects.order_by("pk")[:1].query)
120-
assert result.data["__debug"]["sql"][0]["rawSql"] == query
121-
assert "COUNT" in result.data["__debug"]["sql"][1]["rawSql"]
122-
assert "tests_reporter_pets" in result.data["__debug"]["sql"][2]["rawSql"]
123-
assert "COUNT" in result.data["__debug"]["sql"][3]["rawSql"]
124-
assert "tests_reporter_pets" in result.data["__debug"]["sql"][4]["rawSql"]
125-
assert len(result.data["__debug"]["sql"]) == 5
120+
assert result.data["_debug"]["sql"][0]["rawSql"] == query
121+
assert "COUNT" in result.data["_debug"]["sql"][1]["rawSql"]
122+
assert "tests_reporter_pets" in result.data["_debug"]["sql"][2]["rawSql"]
123+
assert "COUNT" in result.data["_debug"]["sql"][3]["rawSql"]
124+
assert "tests_reporter_pets" in result.data["_debug"]["sql"][4]["rawSql"]
125+
assert len(result.data["_debug"]["sql"]) == 5
126126

127127
assert result.data["reporter"] == expected["reporter"]
128128

graphene_django/fields.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from functools import partial
22

3-
import six
43
from django.db.models.query import QuerySet
5-
from graphql_relay.connection.arrayconnection import connection_from_list_slice
4+
from graphene.relay.connection import page_info_adapter, connection_adapter
5+
6+
from graphql_relay.connection.arrayconnection import connection_from_array_slice
67
from promise import Promise
78

89
from graphene import NonNull
9-
from graphene.relay import ConnectionField, PageInfo
10+
from graphene.relay import ConnectionField
1011
from graphene.types import Field, List
1112

1213
from .settings import graphene_settings
@@ -123,15 +124,15 @@ def resolve_connection(cls, connection, args, iterable):
123124
_len = iterable.count()
124125
else:
125126
_len = len(iterable)
126-
connection = connection_from_list_slice(
127+
connection = connection_from_array_slice(
127128
iterable,
128129
args,
129130
slice_start=0,
130-
list_length=_len,
131-
list_slice_length=_len,
132-
connection_type=connection,
131+
array_length=_len,
132+
array_slice_length=_len,
133+
connection_type=partial(connection_adapter, connection),
133134
edge_type=connection.Edge,
134-
pageinfo_type=PageInfo,
135+
page_info_type=page_info_adapter,
135136
)
136137
connection.iterable = iterable
137138
connection.length = _len

graphene_django/filter/filterset.py

+1-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import itertools
22

33
from django.db import models
4-
from django_filters import Filter, MultipleChoiceFilter, VERSION
4+
from django_filters import Filter, MultipleChoiceFilter
55
from django_filters.filterset import BaseFilterSet, FilterSet
66
from django_filters.filterset import FILTER_FOR_DBFIELD_DEFAULTS
77

@@ -50,36 +50,6 @@ class GrapheneFilterSetMixin(BaseFilterSet):
5050
)
5151

5252

53-
# To support a Django 1.11 + Python 2.7 combination django-filter must be
54-
# < 2.x.x. To support the earlier version of django-filter, the
55-
# filter_for_reverse_field method must be present on GrapheneFilterSetMixin and
56-
# must not be present for later versions of django-filter.
57-
if VERSION[0] < 2:
58-
from django.utils.text import capfirst
59-
60-
class GrapheneFilterSetMixinPython2(GrapheneFilterSetMixin):
61-
@classmethod
62-
def filter_for_reverse_field(cls, f, name):
63-
"""Handles retrieving filters for reverse relationships
64-
We override the default implementation so that we can handle
65-
Global IDs (the default implementation expects database
66-
primary keys)
67-
"""
68-
try:
69-
rel = f.field.remote_field
70-
except AttributeError:
71-
rel = f.field.rel
72-
default = {"name": name, "label": capfirst(rel.related_name)}
73-
if rel.multiple:
74-
# For to-many relationships
75-
return GlobalIDMultipleChoiceFilter(**default)
76-
else:
77-
# For to-one relationships
78-
return GlobalIDFilter(**default)
79-
80-
GrapheneFilterSetMixin = GrapheneFilterSetMixinPython2
81-
82-
8353
def setup_filterset(filterset_class):
8454
""" Wrap a provided filterset in Graphene-specific functionality
8555
"""

0 commit comments

Comments
 (0)