Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…jango into bugfix/multiple_model_serializers
  • Loading branch information
Hispar committed May 24, 2019
2 parents 1e76903 + b0cba39 commit 97461d1
Show file tree
Hide file tree
Showing 63 changed files with 1,671 additions and 523 deletions.
14 changes: 11 additions & 3 deletions .travis.yml
@@ -1,19 +1,21 @@
language: python
sudo: false
sudo: required
dist: xenial
python:
- 2.7
- 3.4
- 3.5
- 3.6
- 3.7
install:
- |
if [ "$TEST_TYPE" = build ]; then
pip install -e .[test]
pip install psycopg2 # Required for Django postgres fields testing
pip install psycopg2==2.8.2 # Required for Django postgres fields testing
pip install django==$DJANGO_VERSION
python setup.py develop
elif [ "$TEST_TYPE" = lint ]; then
pip install flake8
pip install flake8==3.7.7
fi
script:
- |
Expand Down Expand Up @@ -45,10 +47,16 @@ matrix:
env: TEST_TYPE=build DJANGO_VERSION=2.1
- python: '3.6'
env: TEST_TYPE=build DJANGO_VERSION=2.1
- python: '3.6'
env: TEST_TYPE=build DJANGO_VERSION=2.2
- python: '3.7'
env: TEST_TYPE=build DJANGO_VERSION=2.2
- python: '2.7'
env: TEST_TYPE=lint
- python: '3.6'
env: TEST_TYPE=lint
- python: '3.7'
env: TEST_TYPE=lint
deploy:
provider: pypi
user: syrusakbary
Expand Down
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at me@syrusakbary.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
62 changes: 62 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,62 @@
# Contributing

Thanks for helping to make graphene-django great!

We welcome all kinds of contributions:

- Bug fixes
- Documentation improvements
- New features
- Refactoring & tidying


## Getting started

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.


## Project setup

After cloning this repo, ensure dependencies are installed by running:

```sh
make dev-setup
```

## Running tests

After developing, the full test suite can be evaluated by running:

```sh
make tests
```

## Opening Pull Requests

Please fork the project and open a pull request against the master branch.

This will trigger a series of test and lint checks.

We advise that you format and run lint locally before doing this to save time:

```sh
make format
make lint
```

## Documentation

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.

The documentation dependencies are installed by running:

```sh
cd docs
pip install -r requirements.txt
```

Then to produce a HTML version of the documentation:

```sh
make html
```
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -1,2 +1,3 @@
include README.md LICENSE
recursive-include graphene_django/templates *
recursive-include graphene_django/static *
11 changes: 11 additions & 0 deletions Makefile
@@ -0,0 +1,11 @@
dev-setup:
pip install -e ".[dev]"

tests:
py.test graphene_django --cov=graphene_django -vv

format:
black graphene_django

lint:
flake8 graphene_django
39 changes: 8 additions & 31 deletions README.md
Expand Up @@ -7,7 +7,11 @@ Please read [UPGRADE-v2.0.md](https://github.com/graphql-python/graphene/blob/ma

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

## Installation
## Documentation

[Visit the documentation to get started!](https://docs.graphene-python.org/projects/django/en/latest/)

## Quickstart

For installing graphene, just run this command in your shell

Expand All @@ -20,6 +24,7 @@ pip install "graphene-django>=2.0"
```python
INSTALLED_APPS = (
# ...
'django.contrib.staticfiles', # Required for GraphiQL
'graphene_django',
)

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

urlpatterns = [
# ...
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
url(r'^graphql$', GraphQLView.as_view(graphiql=True)),
]
```

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

## Contributing

After cloning this repo, ensure dependencies are installed by running:

```sh
pip install -e ".[test]"
```

After developing, the full test suite can be evaluated by running:

```sh
py.test graphene_django --cov=graphene_django # Use -v -s for verbose mode
```


### Documentation

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.

The documentation dependencies are installed by running:

```sh
cd docs
pip install -r requirements.txt
```

Then to produce a HTML version of the documentation:

```sh
make html
```
See [CONTRIBUTING.md](CONTRIBUTING.md)
43 changes: 10 additions & 33 deletions README.rst
Expand Up @@ -10,8 +10,14 @@ to learn how to upgrade to Graphene ``2.0``.
A `Django <https://www.djangoproject.com/>`__ integration for
`Graphene <http://graphene-python.org/>`__.

Installation
------------

Documentation
-------------

`Visit the documentation to get started! <https://docs.graphene-python.org/projects/django/en/latest/>`__

Quickstart
----------

For installing graphene, just run this command in your shell

Expand Down Expand Up @@ -46,7 +52,7 @@ serve the queries.
urlpatterns = [
# ...
url(r'^graphql', GraphQLView.as_view(graphiql=True)),
url(r'^graphql$', GraphQLView.as_view(graphiql=True)),
]
Examples
Expand Down Expand Up @@ -105,36 +111,7 @@ To learn more check out the following `examples <examples/>`__:
Contributing
------------

After cloning this repo, ensure dependencies are installed by running:

.. code:: sh
pip install -e ".[test]"
After developing, the full test suite can be evaluated by running:

.. code:: sh
py.test graphene_django --cov=graphene_django # Use -v -s for verbose mode
Documentation
~~~~~~~~~~~~~

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.

The documentation dependencies are installed by running:

.. code:: sh
cd docs
pip install -r requirements.txt
Then to produce a HTML version of the documentation:

.. code:: sh
make html
See `CONTRIBUTING.md <CONTRIBUTING.md>`__.

.. |Graphene Logo| image:: http://graphene-python.org/favicon.png
.. |Build Status| image:: https://travis-ci.org/graphql-python/graphene-django.svg?branch=master
Expand Down
31 changes: 27 additions & 4 deletions docs/authorization.rst
Expand Up @@ -96,6 +96,29 @@ schema is simple.
result = schema.execute(query, context_value=request)
Global Filtering
----------------

If you are using ``DjangoObjectType`` you can define a custom `get_queryset`.

.. code:: python
from graphene import relay
from graphene_django.types import DjangoObjectType
from .models import Post
class PostNode(DjangoObjectType):
class Meta:
model = Post
@classmethod
def get_queryset(cls, queryset, info):
if info.context.user.is_anonymous:
return queryset.filter(published=True)
return queryset
Filtering ID-based Node Access
------------------------------

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

.. code:: python
#views.py
from django.contrib.auth.mixins import LoginRequiredMixin
from graphene_django.views import GraphQLView
Expand All @@ -148,9 +171,9 @@ For Django 1.9 and below:
urlpatterns = [
# some other urls
url(r'^graphql', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
url(r'^graphql$', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
]
For Django 2.0 and above:

.. code:: python
Expand Down

0 comments on commit 97461d1

Please sign in to comment.