Skip to content

Commit c0fbed2

Browse files
authored
Merge pull request #624 from graphql-python/docs-improvements
Docs improvements
2 parents 6f03597 + 15b5e6a commit c0fbed2

19 files changed

+768
-215
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ Please read [UPGRADE-v2.0.md](https://github.com/graphql-python/graphene/blob/ma
77

88
A [Django](https://www.djangoproject.com/) integration for [Graphene](http://graphene-python.org/).
99

10-
## Installation
10+
## Documentation
11+
12+
[Visit the documentation to get started!](https://docs.graphene-python.org/projects/django/en/latest/)
13+
14+
## Quickstart
1115

1216
For installing graphene, just run this command in your shell
1317

@@ -39,7 +43,7 @@ from graphene_django.views import GraphQLView
3943

4044
urlpatterns = [
4145
# ...
42-
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
46+
url(r'^graphql$', GraphQLView.as_view(graphiql=True)),
4347
]
4448
```
4549

README.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ to learn how to upgrade to Graphene ``2.0``.
1010
A `Django <https://www.djangoproject.com/>`__ integration for
1111
`Graphene <http://graphene-python.org/>`__.
1212

13-
Installation
14-
------------
13+
14+
Documentation
15+
-------------
16+
17+
`Visit the documentation to get started! <https://docs.graphene-python.org/projects/django/en/latest/>`__
18+
19+
Quickstart
20+
----------
1521

1622
For installing graphene, just run this command in your shell
1723

@@ -46,7 +52,7 @@ serve the queries.
4652
4753
urlpatterns = [
4854
# ...
49-
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
55+
url(r'^graphql$', GraphQLView.as_view(graphiql=True)),
5056
]
5157
5258
Examples

docs/authorization.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ To restrict users from accessing the GraphQL API page the standard Django LoginR
155155

156156
.. code:: python
157157
#views.py
158-
158+
159159
from django.contrib.auth.mixins import LoginRequiredMixin
160160
from graphene_django.views import GraphQLView
161161
@@ -171,9 +171,9 @@ For Django 1.9 and below:
171171
172172
urlpatterns = [
173173
# some other urls
174-
url(r'^graphql', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
174+
url(r'^graphql$', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
175175
]
176-
176+
177177
For Django 2.0 and above:
178178

179179
.. code:: python

docs/conf.py

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22

3-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
3+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
44

55
# -*- coding: utf-8 -*-
66
#
@@ -34,46 +34,44 @@
3434
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3535
# ones.
3636
extensions = [
37-
'sphinx.ext.autodoc',
38-
'sphinx.ext.intersphinx',
39-
'sphinx.ext.todo',
40-
'sphinx.ext.coverage',
41-
'sphinx.ext.viewcode',
37+
"sphinx.ext.autodoc",
38+
"sphinx.ext.intersphinx",
39+
"sphinx.ext.todo",
40+
"sphinx.ext.coverage",
41+
"sphinx.ext.viewcode",
4242
]
4343
if not on_rtd:
44-
extensions += [
45-
'sphinx.ext.githubpages',
46-
]
44+
extensions += ["sphinx.ext.githubpages"]
4745

4846
# Add any paths that contain templates here, relative to this directory.
49-
templates_path = ['_templates']
47+
templates_path = ["_templates"]
5048

5149
# The suffix(es) of source filenames.
5250
# You can specify multiple suffix as a list of string:
5351
#
5452
# source_suffix = ['.rst', '.md']
55-
source_suffix = '.rst'
53+
source_suffix = ".rst"
5654

5755
# The encoding of source files.
5856
#
5957
# source_encoding = 'utf-8-sig'
6058

6159
# The master toctree document.
62-
master_doc = 'index'
60+
master_doc = "index"
6361

6462
# General information about the project.
65-
project = u'Graphene Django'
66-
copyright = u'Graphene 2017'
67-
author = u'Syrus Akbary'
63+
project = u"Graphene Django"
64+
copyright = u"Graphene 2017"
65+
author = u"Syrus Akbary"
6866

6967
# The version info for the project you're documenting, acts as replacement for
7068
# |version| and |release|, also used in various other places throughout the
7169
# built documents.
7270
#
7371
# The short X.Y version.
74-
version = u'1.0'
72+
version = u"1.0"
7573
# The full version, including alpha/beta/rc tags.
76-
release = u'1.0.dev'
74+
release = u"1.0.dev"
7775

7876
# The language for content autogenerated by Sphinx. Refer to documentation
7977
# for a list of supported languages.
@@ -94,7 +92,7 @@
9492
# List of patterns, relative to source directory, that match files and
9593
# directories to ignore when looking for source files.
9694
# This patterns also effect to html_static_path and html_extra_path
97-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
95+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
9896

9997
# The reST default role (used for this markup: `text`) to use for all
10098
# documents.
@@ -116,7 +114,7 @@
116114
# show_authors = False
117115

118116
# The name of the Pygments (syntax highlighting) style to use.
119-
pygments_style = 'sphinx'
117+
pygments_style = "sphinx"
120118

121119
# A list of ignored prefixes for module index sorting.
122120
# modindex_common_prefix = []
@@ -175,7 +173,7 @@
175173
# Add any paths that contain custom static files (such as style sheets) here,
176174
# relative to this directory. They are copied after the builtin static files,
177175
# so a file named "default.css" will overwrite the builtin "default.css".
178-
html_static_path = ['_static']
176+
html_static_path = ["_static"]
179177

180178
# Add any extra paths that contain custom files (such as robots.txt or
181179
# .htaccess) here, relative to this directory. These files are copied
@@ -255,34 +253,30 @@
255253
# html_search_scorer = 'scorer.js'
256254

257255
# Output file base name for HTML help builder.
258-
htmlhelp_basename = 'Graphenedoc'
256+
htmlhelp_basename = "Graphenedoc"
259257

260258
# -- Options for LaTeX output ---------------------------------------------
261259

262260
latex_elements = {
263-
# The paper size ('letterpaper' or 'a4paper').
264-
#
265-
# 'papersize': 'letterpaper',
266-
267-
# The font size ('10pt', '11pt' or '12pt').
268-
#
269-
# 'pointsize': '10pt',
270-
271-
# Additional stuff for the LaTeX preamble.
272-
#
273-
# 'preamble': '',
274-
275-
# Latex figure (float) alignment
276-
#
277-
# 'figure_align': 'htbp',
261+
# The paper size ('letterpaper' or 'a4paper').
262+
#
263+
# 'papersize': 'letterpaper',
264+
# The font size ('10pt', '11pt' or '12pt').
265+
#
266+
# 'pointsize': '10pt',
267+
# Additional stuff for the LaTeX preamble.
268+
#
269+
# 'preamble': '',
270+
# Latex figure (float) alignment
271+
#
272+
# 'figure_align': 'htbp',
278273
}
279274

280275
# Grouping the document tree into LaTeX files. List of tuples
281276
# (source start file, target name, title,
282277
# author, documentclass [howto, manual, or own class]).
283278
latex_documents = [
284-
(master_doc, 'Graphene.tex', u'Graphene Documentation',
285-
u'Syrus Akbary', 'manual'),
279+
(master_doc, "Graphene.tex", u"Graphene Documentation", u"Syrus Akbary", "manual")
286280
]
287281

288282
# The name of an image file (relative to this directory) to place at the top of
@@ -323,8 +317,7 @@
323317
# One entry per manual page. List of tuples
324318
# (source start file, name, description, authors, manual section).
325319
man_pages = [
326-
(master_doc, 'graphene_django', u'Graphene Django Documentation',
327-
[author], 1)
320+
(master_doc, "graphene_django", u"Graphene Django Documentation", [author], 1)
328321
]
329322

330323
# If true, show URL addresses after external links.
@@ -338,9 +331,15 @@
338331
# (source start file, target name, title, author,
339332
# dir menu entry, description, category)
340333
texinfo_documents = [
341-
(master_doc, 'Graphene-Django', u'Graphene Django Documentation',
342-
author, 'Graphene Django', 'One line description of project.',
343-
'Miscellaneous'),
334+
(
335+
master_doc,
336+
"Graphene-Django",
337+
u"Graphene Django Documentation",
338+
author,
339+
"Graphene Django",
340+
"One line description of project.",
341+
"Miscellaneous",
342+
)
344343
]
345344

346345
# Documents to append as an appendix to all manuals.
@@ -414,7 +413,7 @@
414413
# epub_post_files = []
415414

416415
# A list of files that should not be packed into the epub file.
417-
epub_exclude_files = ['search.html']
416+
epub_exclude_files = ["search.html"]
418417

419418
# The depth of the table of contents in toc.ncx.
420419
#
@@ -446,4 +445,4 @@
446445

447446

448447
# Example configuration for intersphinx: refer to the Python standard library.
449-
intersphinx_mapping = {'https://docs.python.org/': None}
448+
intersphinx_mapping = {"https://docs.python.org/": None}

docs/debug.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ And in your ``settings.py``:
3434
.. code:: python
3535
3636
GRAPHENE = {
37+
...
3738
'MIDDLEWARE': [
3839
'graphene_django.debug.DjangoDebugMiddleware',
3940
]

docs/filtering.rst

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pre-filter animals owned by the authenticated user (set in ``context.user``).
136136
137137
class AnimalFilter(django_filters.FilterSet):
138138
# Do case-insensitive lookups on 'name'
139-
name = django_filters.CharFilter(lookup_type='iexact')
139+
name = django_filters.CharFilter(lookup_type=['iexact'])
140140
141141
class Meta:
142142
model = Animal
@@ -146,3 +146,49 @@ pre-filter animals owned by the authenticated user (set in ``context.user``).
146146
def qs(self):
147147
# The query context can be found in self.request.
148148
return super(AnimalFilter, self).qs.filter(owner=self.request.user)
149+
150+
151+
Ordering
152+
--------
153+
154+
You can use ``OrderFilter`` to define how you want your returned results to be ordered.
155+
156+
Extend the tuple of fields if you want to order by more than one field.
157+
158+
.. code:: python
159+
160+
from django_filters import FilterSet, OrderingFilter
161+
162+
class UserFilter(FilterSet):
163+
class Meta:
164+
model = UserModel
165+
166+
order_by = OrderingFilter(
167+
fields=(
168+
('created_at', 'created_at'),
169+
)
170+
)
171+
172+
class Group(DjangoObjectType):
173+
users = DjangoFilterConnectionField(Ticket, filterset_class=UserFilter)
174+
175+
class Meta:
176+
name = 'Group'
177+
model = GroupModel
178+
interfaces = (relay.Node,)
179+
180+
def resolve_users(self, info, **kwargs):
181+
return UserFilter(kwargs).qs
182+
183+
184+
with this set up, you can now order the users under group:
185+
186+
.. code::
187+
188+
query {
189+
group(id: "xxx") {
190+
users(orderBy: "-created_at") {
191+
xxx
192+
}
193+
}
194+
}

0 commit comments

Comments
 (0)