Skip to content

Commit 73f4a92

Browse files
committed
Merge branch 'master' into recursive-nodes
2 parents 3e5ae5a + 31fdb5a commit 73f4a92

File tree

24 files changed

+305
-49
lines changed

24 files changed

+305
-49
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ To create a GraphQL schema for it you simply have to write the following:
5858

5959
```python
6060
from graphene_django import DjangoObjectType
61+
import graphene
6162

6263
class User(DjangoObjectType):
6364
class Meta:
@@ -106,3 +107,21 @@ After developing, the full test suite can be evaluated by running:
106107
```sh
107108
python setup.py test # Use --pytest-args="-v -s" for verbose mode
108109
```
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ following:
6868
.. code:: python
6969
7070
from graphene_django import DjangoObjectType
71+
import graphene
7172
7273
class User(DjangoObjectType):
7374
class Meta:
@@ -116,6 +117,25 @@ After developing, the full test suite can be evaluated by running:
116117
117118
python setup.py test # Use --pytest-args="-v -s" for verbose mode
118119
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+
119139
.. |Graphene Logo| image:: http://graphene-python.org/favicon.png
120140
.. |Build Status| image:: https://travis-ci.org/graphql-python/graphene-django.svg?branch=master
121141
: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

examples/cookbook/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ Now you should be ready to start the server:
6060
Now head on over to
6161
[http://127.0.0.1:8000/graphql](http://127.0.0.1:8000/graphql)
6262
and run some queries!
63-
(See the [Django quickstart guide](http://graphene-python.org/docs/quickstart-django/)
63+
(See the [Graphene-Django Tutorial](http://docs.graphene-python.org/projects/django/en/latest/tutorial.html#testing-our-graphql-schema)
6464
for some example queries)

examples/cookbook/cookbook/ingredients/admin.py

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

33
from cookbook.ingredients.models import Category, Ingredient
44

5-
admin.site.register(Ingredient)
5+
@admin.register(Ingredient)
6+
class IngredientAdmin(admin.ModelAdmin):
7+
list_display = ("id","name","category")
8+
list_editable = ("name","category")
9+
610
admin.site.register(Category)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9 on 2016-11-04 00:50
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('ingredients', '0001_initial'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='ingredient',
17+
name='notes',
18+
field=models.TextField(blank=True, null=True),
19+
),
20+
]

examples/cookbook/cookbook/ingredients/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def __str__(self):
1010

1111
class Ingredient(models.Model):
1212
name = models.CharField(max_length=100)
13-
notes = models.TextField()
13+
notes = models.TextField(null=True,blank=True)
1414
category = models.ForeignKey(Category, related_name='ingredients')
1515

1616
def __str__(self):

examples/cookbook/cookbook/ingredients/schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from cookbook.ingredients.models import Category, Ingredient
2-
from graphene import AbstractType, Field, Node
2+
from graphene import AbstractType, Node
33
from graphene_django.filter import DjangoFilterConnectionField
44
from graphene_django.types import DjangoObjectType
55

@@ -31,8 +31,8 @@ class Meta:
3131

3232

3333
class Query(AbstractType):
34-
category = Field(CategoryNode)
34+
category = Node.Field(CategoryNode)
3535
all_categories = DjangoFilterConnectionField(CategoryNode)
3636

37-
ingredient = Field(IngredientNode)
37+
ingredient = Node.Field(IngredientNode)
3838
all_ingredients = DjangoFilterConnectionField(IngredientNode)

examples/cookbook/cookbook/recipes/admin.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@
22

33
from cookbook.recipes.models import Recipe, RecipeIngredient
44

5-
admin.site.register(Recipe)
6-
admin.site.register(RecipeIngredient)
5+
class RecipeIngredientInline(admin.TabularInline):
6+
model = RecipeIngredient
7+
8+
@admin.register(Recipe)
9+
class RecipeAdmin(admin.ModelAdmin):
10+
inlines = [RecipeIngredientInline]

0 commit comments

Comments
 (0)