Skip to content

Commit 97461d1

Browse files
committed
Merge branch 'master' of https://github.com/graphql-python/graphene-django into bugfix/multiple_model_serializers
2 parents 1e76903 + b0cba39 commit 97461d1

Some content is hidden

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

63 files changed

+1671
-523
lines changed

.travis.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
language: python
2-
sudo: false
2+
sudo: required
3+
dist: xenial
34
python:
45
- 2.7
56
- 3.4
67
- 3.5
78
- 3.6
9+
- 3.7
810
install:
911
- |
1012
if [ "$TEST_TYPE" = build ]; then
1113
pip install -e .[test]
12-
pip install psycopg2 # Required for Django postgres fields testing
14+
pip install psycopg2==2.8.2 # Required for Django postgres fields testing
1315
pip install django==$DJANGO_VERSION
1416
python setup.py develop
1517
elif [ "$TEST_TYPE" = lint ]; then
16-
pip install flake8
18+
pip install flake8==3.7.7
1719
fi
1820
script:
1921
- |
@@ -45,10 +47,16 @@ matrix:
4547
env: TEST_TYPE=build DJANGO_VERSION=2.1
4648
- python: '3.6'
4749
env: TEST_TYPE=build DJANGO_VERSION=2.1
50+
- python: '3.6'
51+
env: TEST_TYPE=build DJANGO_VERSION=2.2
52+
- python: '3.7'
53+
env: TEST_TYPE=build DJANGO_VERSION=2.2
4854
- python: '2.7'
4955
env: TEST_TYPE=lint
5056
- python: '3.6'
5157
env: TEST_TYPE=lint
58+
- python: '3.7'
59+
env: TEST_TYPE=lint
5260
deploy:
5361
provider: pypi
5462
user: syrusakbary

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to making participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies both within project spaces and in public spaces
49+
when an individual is representing the project or its community. Examples of
50+
representing a project or community include using an official project e-mail
51+
address, posting via an official social media account, or acting as an appointed
52+
representative at an online or offline event. Representation of a project may be
53+
further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

CONTRIBUTING.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Contributing
2+
3+
Thanks for helping to make graphene-django great!
4+
5+
We welcome all kinds of contributions:
6+
7+
- Bug fixes
8+
- Documentation improvements
9+
- New features
10+
- Refactoring & tidying
11+
12+
13+
## Getting started
14+
15+
If you have a specific contribution in mind, be sure to check the [issues](https://github.com/graphql-python/graphene-django/issues) and [projects](https://github.com/graphql-python/graphene-django/projects) in progress - someone could already be working on something similar and you can help out.
16+
17+
18+
## Project setup
19+
20+
After cloning this repo, ensure dependencies are installed by running:
21+
22+
```sh
23+
make dev-setup
24+
```
25+
26+
## Running tests
27+
28+
After developing, the full test suite can be evaluated by running:
29+
30+
```sh
31+
make tests
32+
```
33+
34+
## Opening Pull Requests
35+
36+
Please fork the project and open a pull request against the master branch.
37+
38+
This will trigger a series of test and lint checks.
39+
40+
We advise that you format and run lint locally before doing this to save time:
41+
42+
```sh
43+
make format
44+
make lint
45+
```
46+
47+
## Documentation
48+
49+
The [documentation](http://docs.graphene-python.org/projects/django/en/latest/) is generated using the excellent [Sphinx](http://www.sphinx-doc.org/) and a custom theme.
50+
51+
The documentation dependencies are installed by running:
52+
53+
```sh
54+
cd docs
55+
pip install -r requirements.txt
56+
```
57+
58+
Then to produce a HTML version of the documentation:
59+
60+
```sh
61+
make html
62+
```

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
include README.md LICENSE
22
recursive-include graphene_django/templates *
3+
recursive-include graphene_django/static *

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
dev-setup:
2+
pip install -e ".[dev]"
3+
4+
tests:
5+
py.test graphene_django --cov=graphene_django -vv
6+
7+
format:
8+
black graphene_django
9+
10+
lint:
11+
flake8 graphene_django

README.md

Lines changed: 8 additions & 31 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

@@ -20,6 +24,7 @@ pip install "graphene-django>=2.0"
2024
```python
2125
INSTALLED_APPS = (
2226
# ...
27+
'django.contrib.staticfiles', # Required for GraphiQL
2328
'graphene_django',
2429
)
2530

@@ -38,7 +43,7 @@ from graphene_django.views import GraphQLView
3843

3944
urlpatterns = [
4045
# ...
41-
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
46+
url(r'^graphql$', GraphQLView.as_view(graphiql=True)),
4247
]
4348
```
4449

@@ -95,32 +100,4 @@ To learn more check out the following [examples](examples/):
95100

96101
## Contributing
97102

98-
After cloning this repo, ensure dependencies are installed by running:
99-
100-
```sh
101-
pip install -e ".[test]"
102-
```
103-
104-
After developing, the full test suite can be evaluated by running:
105-
106-
```sh
107-
py.test graphene_django --cov=graphene_django # Use -v -s for verbose mode
108-
```
109-
110-
111-
### Documentation
112-
113-
The [documentation](http://docs.graphene-python.org/projects/django/en/latest/) is generated using the excellent [Sphinx](http://www.sphinx-doc.org/) and a custom theme.
114-
115-
The documentation dependencies are installed by running:
116-
117-
```sh
118-
cd docs
119-
pip install -r requirements.txt
120-
```
121-
122-
Then to produce a HTML version of the documentation:
123-
124-
```sh
125-
make html
126-
```
103+
See [CONTRIBUTING.md](CONTRIBUTING.md)

README.rst

Lines changed: 10 additions & 33 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
@@ -105,36 +111,7 @@ To learn more check out the following `examples <examples/>`__:
105111
Contributing
106112
------------
107113

108-
After cloning this repo, ensure dependencies are installed by running:
109-
110-
.. code:: sh
111-
112-
pip install -e ".[test]"
113-
114-
After developing, the full test suite can be evaluated by running:
115-
116-
.. code:: sh
117-
118-
py.test graphene_django --cov=graphene_django # Use -v -s for verbose mode
119-
120-
Documentation
121-
~~~~~~~~~~~~~
122-
123-
The `documentation <http://docs.graphene-python.org/projects/django/en/latest/>`__ is generated using the excellent
124-
`Sphinx <http://www.sphinx-doc.org/>`__ and a custom theme.
125-
126-
The documentation dependencies are installed by running:
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
114+
See `CONTRIBUTING.md <CONTRIBUTING.md>`__.
138115

139116
.. |Graphene Logo| image:: http://graphene-python.org/favicon.png
140117
.. |Build Status| image:: https://travis-ci.org/graphql-python/graphene-django.svg?branch=master

docs/authorization.rst

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,29 @@ schema is simple.
9696
9797
result = schema.execute(query, context_value=request)
9898
99+
100+
Global Filtering
101+
----------------
102+
103+
If you are using ``DjangoObjectType`` you can define a custom `get_queryset`.
104+
105+
.. code:: python
106+
107+
from graphene import relay
108+
from graphene_django.types import DjangoObjectType
109+
from .models import Post
110+
111+
class PostNode(DjangoObjectType):
112+
class Meta:
113+
model = Post
114+
115+
@classmethod
116+
def get_queryset(cls, queryset, info):
117+
if info.context.user.is_anonymous:
118+
return queryset.filter(published=True)
119+
return queryset
120+
121+
99122
Filtering ID-based Node Access
100123
------------------------------
101124

@@ -114,7 +137,7 @@ method to your ``DjangoObjectType``.
114137
interfaces = (relay.Node, )
115138
116139
@classmethod
117-
def get_node(cls, id, info):
140+
def get_node(cls, info, id):
118141
try:
119142
post = cls._meta.model.objects.get(id=id)
120143
except cls._meta.model.DoesNotExist:
@@ -132,7 +155,7 @@ To restrict users from accessing the GraphQL API page the standard Django LoginR
132155

133156
.. code:: python
134157
#views.py
135-
158+
136159
from django.contrib.auth.mixins import LoginRequiredMixin
137160
from graphene_django.views import GraphQLView
138161
@@ -148,9 +171,9 @@ For Django 1.9 and below:
148171
149172
urlpatterns = [
150173
# some other urls
151-
url(r'^graphql', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
174+
url(r'^graphql$', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
152175
]
153-
176+
154177
For Django 2.0 and above:
155178

156179
.. code:: python

0 commit comments

Comments
 (0)