Skip to content

Commit 297b741

Browse files
Merge pull request #1 from graphql-python/master
Catch up with parent repo
2 parents d524718 + d8567f1 commit 297b741

File tree

13 files changed

+107
-25
lines changed

13 files changed

+107
-25
lines changed

.travis.yml

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ python:
66
- 3.5
77
- pypy
88
before_install:
9-
- |
10-
if [ "$TRAVIS_PYTHON_VERSION" = "pypy" ]; then
11-
export PYENV_ROOT="$HOME/.pyenv"
12-
if [ -f "$PYENV_ROOT/bin/pyenv" ]; then
13-
cd "$PYENV_ROOT" && git pull
14-
else
15-
rm -rf "$PYENV_ROOT" && git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
16-
fi
17-
export PYPY_VERSION="4.0.1"
18-
"$PYENV_ROOT/bin/pyenv" install "pypy-$PYPY_VERSION"
19-
virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION"
20-
source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate"
21-
fi
9+
- |
10+
if [ "$TRAVIS_PYTHON_VERSION" = "pypy" ]; then
11+
export PYENV_ROOT="$HOME/.pyenv"
12+
if [ -f "$PYENV_ROOT/bin/pyenv" ]; then
13+
cd "$PYENV_ROOT" && git pull
14+
else
15+
rm -rf "$PYENV_ROOT" && git clone --depth 1 https://github.com/yyuu/pyenv.git "$PYENV_ROOT"
16+
fi
17+
export PYPY_VERSION="4.0.1"
18+
"$PYENV_ROOT/bin/pyenv" install "pypy-$PYPY_VERSION"
19+
virtualenv --python="$PYENV_ROOT/versions/pypy-$PYPY_VERSION/bin/python" "$HOME/virtualenvs/pypy-$PYPY_VERSION"
20+
source "$HOME/virtualenvs/pypy-$PYPY_VERSION/bin/activate"
21+
fi
2222
install:
2323
- |
2424
if [ "$TEST_TYPE" = build ]; then
@@ -59,3 +59,10 @@ matrix:
5959
env: TEST_TYPE=build DJANGO_VERSION=1.9
6060
- python: '2.7'
6161
env: TEST_TYPE=lint
62+
deploy:
63+
provider: pypi
64+
user: syrusakbary
65+
on:
66+
tags: true
67+
password:
68+
secure: kymIFCEPUbkgRqe2NAXkWfxMmGRfWvWBOP6LIXdVdkOOkm91fU7bndPGrAjos+/7gN0Org609ZmHSlVXNMJUWcsL2or/x5LcADJ4cZDe+79qynuoRb9xs1Ri4O4SBAuVMZxuVJvs8oUzT2R11ql5vASSMtXgbX+ZDGpmPRVZStkCuXgOc4LBhbPKyl3OFy7UQFPgAEmy3Yjh4ZSKzlXheK+S6mmr60+DCIjpaA0BWPxYK9FUE0qm7JJbHLUbwsUP/QMp5MmGjwFisXCNsIe686B7QKRaiOw62eJc2R7He8AuEC8T9OM4kRwDlecSn8mMpkoSB7QWtlJ+6XdLrJFPNvtrOfgfzS9/96Qrw9WlOslk68hMlhJeRb0s2YUD8tiV3UUkvbL1mfFoS4SI9U+rojS55KhUEJWHg1w7DjoOPoZmaIL2ChRupmvrFYNAGae1cxwG3Urh+t3wYlN3gpKsRDe5GOT7Wm2tr0ad3McCpDGUwSChX59BAJXe/MoLxkKScTrMyR8yMxHOF0b4zpVn5l7xB/o2Ik4zavx5q/0rGBMK2D+5d+gpQogKShoquTPsZUwO7sB5hYeH2hqGqpeGzZtb76E2zZYd18pJ0FsBudm5+KWjYdZ+vbtGrLxdTXJ1EEtzVXm0lscykTpqUucbXSa51dhStJvW2xEEz6p3rHo=

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,21 @@ After developing, the full test suite can be evaluated by running:
107107
```sh
108108
python setup.py test # Use --pytest-args="-v -s" for verbose mode
109109
```
110+
111+
112+
### Documentation
113+
114+
The documentation is generated using the excellent [Sphinx](http://www.sphinx-doc.org/) and a custom theme.
115+
116+
The documentation dependencies are installed by running:
117+
118+
```sh
119+
cd docs
120+
pip install -r requirements.txt
121+
```
122+
123+
Then to produce a HTML version of the documentation:
124+
125+
```sh
126+
make html
127+
```

README.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,25 @@ After developing, the full test suite can be evaluated by running:
117117
118118
python setup.py test # Use --pytest-args="-v -s" for verbose mode
119119
120+
Documentation
121+
~~~~~~~~~~~~~
122+
123+
The documentation can be generated using the excellent
124+
`Sphinx <http://www.sphinx-doc.org/>`__ and a custom theme.
125+
126+
To install the documentation dependencies, run the following:
127+
128+
.. code:: sh
129+
130+
cd docs
131+
pip install -r requirements.txt
132+
133+
Then to produce a HTML version of the documentation:
134+
135+
.. code:: sh
136+
137+
make html
138+
120139
.. |Graphene Logo| image:: http://graphene-python.org/favicon.png
121140
.. |Build Status| image:: https://travis-ci.org/graphql-python/graphene-django.svg?branch=master
122141
:target: https://travis-ci.org/graphql-python/graphene-django

docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
sphinx
12
# Docs template
23
https://github.com/graphql-python/graphene-python.org/archive/docs.zip

docs/tutorial.rst

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ And then add the ``SCHEMA`` to the ``GRAPHENE`` config in ``cookbook/settings.py
188188
'SCHEMA': 'cookbook.schema.schema'
189189
}
190190
191+
Alternatively, we can specify the schema to be used in the urls definition,
192+
as explained below.
191193

192194
Creating GraphQL and GraphiQL views
193195
-----------------------------------
@@ -199,6 +201,22 @@ view.
199201
This view will serve as GraphQL endpoint. As we want to have the
200202
aforementioned GraphiQL we specify that on the params with ``graphiql=True``.
201203

204+
.. code:: python
205+
206+
from django.conf.urls import url, include
207+
from django.contrib import admin
208+
209+
from graphene_django.views import GraphQLView
210+
211+
urlpatterns = [
212+
url(r'^admin/', admin.site.urls),
213+
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
214+
]
215+
216+
217+
If we didn't specify the target schema in the Django settings file
218+
as explained above, we can do so here using:
219+
202220
.. code:: python
203221
204222
from django.conf.urls import url, include
@@ -210,7 +228,7 @@ aforementioned GraphiQL we specify that on the params with ``graphiql=True``.
210228
211229
urlpatterns = [
212230
url(r'^admin/', admin.site.urls),
213-
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
231+
url(r'^graphql', GraphQLView.as_view(graphiql=True, schema=schema)),
214232
]
215233
216234
Apply model changes to database

graphene_django/compat.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
class MissingType(object):
55
pass
66

7+
78
try:
89
DurationField = models.DurationField
910
UUIDField = models.UUIDField
@@ -21,6 +22,13 @@ class MissingType(object):
2122

2223
try:
2324
# Postgres fields are only available in Django 1.8+
24-
from django.contrib.postgres.fields import ArrayField, HStoreField, JSONField, RangeField
25+
from django.contrib.postgres.fields import ArrayField, HStoreField, RangeField
2526
except ImportError:
2627
ArrayField, HStoreField, JSONField, RangeField = (MissingType, ) * 4
28+
29+
30+
try:
31+
# Postgres fields are only available in Django 1.9+
32+
from django.contrib.postgres.fields import JSONField
33+
except ImportError:
34+
JSONField = MissingType

graphene_django/converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from graphene.relay import is_node
77
from graphene.types.datetime import DateTime
88
from graphene.types.json import JSONString
9-
from graphene.utils.str_converters import to_const
9+
from graphene.utils.str_converters import to_camel_case, to_const
1010
from graphql import assert_valid_name
1111

1212
from .compat import (ArrayField, HStoreField, JSONField, RangeField,
@@ -41,7 +41,7 @@ def convert_django_field_with_choices(field, registry=None):
4141
choices = getattr(field, 'choices', None)
4242
if choices:
4343
meta = field.model._meta
44-
name = '{}{}'.format(meta.object_name, field.name.capitalize())
44+
name = to_camel_case('{}_{}'.format(meta.object_name, field.name))
4545
choices = list(get_choices(choices))
4646
named_choices = [(c[0], c[1]) for c in choices]
4747
named_choices_descriptions = {c[0]: c[2] for c in choices}

graphene_django/templates/graphene/graphiql.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
{% if variables %}
113113
variables: '{{ variables|escapejs }}',
114114
{% endif %}
115-
{% if operationName %}
115+
{% if operation_name %}
116116
operationName: '{{ operation_name|escapejs }}',
117117
{% endif %}
118118
}),

graphene_django/tests/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Article(models.Model):
3838
headline = models.CharField(max_length=100)
3939
pub_date = models.DateField()
4040
reporter = models.ForeignKey(Reporter, related_name='articles')
41+
editor = models.ForeignKey(Reporter, related_name='edited_articles_+')
4142
lang = models.CharField(max_length=2, help_text='Language', choices=[
4243
('es', 'Spanish'),
4344
('en', 'English')

graphene_django/tests/test_types.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_django_objecttype_map_correct_fields():
5252

5353
def test_django_objecttype_with_node_have_correct_fields():
5454
fields = Article._meta.fields
55-
assert list(fields.keys()) == ['id', 'headline', 'pub_date', 'reporter', 'lang', 'importance']
55+
assert list(fields.keys()) == ['id', 'headline', 'pub_date', 'reporter', 'editor', 'lang', 'importance']
5656

5757

5858
def test_schema_representation():
@@ -66,13 +66,14 @@ def test_schema_representation():
6666
headline: String!
6767
pubDate: DateTime!
6868
reporter: Reporter!
69+
editor: Reporter!
6970
lang: ArticleLang!
7071
importance: ArticleImportance
7172
}
7273
7374
type ArticleConnection {
7475
pageInfo: PageInfo!
75-
edges: [ArticleEdge]
76+
edges: [ArticleEdge]!
7677
}
7778
7879
type ArticleEdge {
@@ -109,11 +110,11 @@ def test_schema_representation():
109110
lastName: String!
110111
email: String!
111112
pets: [Reporter]
112-
aChoice: ReporterA_choice!
113+
aChoice: ReporterAChoice!
113114
articles(before: String, after: String, first: Int, last: Int): ArticleConnection
114115
}
115116
116-
enum ReporterA_choice {
117+
enum ReporterAChoice {
117118
A_1
118119
A_2
119120
}

graphene_django/types.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ def construct_fields(options):
2626
is_not_in_only = only_fields and name not in options.only_fields
2727
is_already_created = name in options.fields
2828
is_excluded = name in exclude_fields or is_already_created
29-
if is_not_in_only or is_excluded:
29+
# https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.ForeignKey.related_query_name
30+
is_no_backref = str(name).endswith('+')
31+
if is_not_in_only or is_excluded or is_no_backref:
3032
# We skip this field if we specify only_fields and is not
31-
# in there. Or when we exclude this field in exclude_fields
33+
# in there. Or when we exclude this field in exclude_fields.
34+
# Or when there is no back reference.
3235
continue
3336
converted = convert_django_field_with_choices(field, options.registry)
3437
if not converted:

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[aliases]
2+
test=pytest
3+
14
[tool:pytest]
25
DJANGO_SETTINGS_MODULE = django_test_settings
36

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='graphene-django',
5-
version='1.0',
5+
version='1.1.0',
66

77
description='Graphene Django integration',
88
long_description=open('README.rst').read(),
@@ -38,6 +38,9 @@
3838
'iso8601',
3939
'singledispatch>=3.4.0.3',
4040
],
41+
setup_requires=[
42+
'pytest-runner',
43+
],
4144
tests_require=[
4245
'django-filter>=0.10.0',
4346
'pytest',

0 commit comments

Comments
 (0)