Skip to content

Commit a8e341b

Browse files
authored
Merge branch 'main' into debug-middleware-sql-bytes
2 parents 7e6bf08 + be17278 commit a8e341b

File tree

96 files changed

+2329
-815
lines changed

Some content is hidden

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

96 files changed

+2329
-815
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ a github repo, https://repl.it or similar (you can use this template as a starti
2727

2828

2929
* **Please tell us about your environment:**
30-
31-
- Version:
32-
- Platform:
30+
31+
- Version:
32+
- Platform:
3333

3434
* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)

.github/workflows/deploy.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/checkout@v2
14-
- name: Set up Python 3.9
15-
uses: actions/setup-python@v2
13+
- uses: actions/checkout@v3
14+
- name: Set up Python 3.11
15+
uses: actions/setup-python@v4
1616
with:
17-
python-version: 3.9
17+
python-version: '3.11'
1818
- name: Build wheel and source tarball
1919
run: |
2020
pip install wheel
2121
python setup.py sdist bdist_wheel
2222
- name: Publish a Python distribution to PyPI
23-
uses: pypa/gh-action-pypi-publish@v1.1.0
23+
uses: pypa/gh-action-pypi-publish@v1.8.6
2424
with:
2525
user: __token__
2626
password: ${{ secrets.pypi_password }}

.github/workflows/lint.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v2
11-
- name: Set up Python 3.9
12-
uses: actions/setup-python@v2
10+
- uses: actions/checkout@v3
11+
- name: Set up Python 3.11
12+
uses: actions/setup-python@v4
1313
with:
14-
python-version: 3.9
14+
python-version: '3.11'
1515
- name: Install dependencies
1616
run: |
1717
python -m pip install --upgrade pip
1818
pip install tox
19-
- name: Run lint 💅
19+
- name: Run pre-commit 💅
2020
run: tox
2121
env:
22-
TOXENV: flake8
22+
TOXENV: pre-commit

.github/workflows/tests.yml

+7-9
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,17 @@ jobs:
88
strategy:
99
max-parallel: 4
1010
matrix:
11-
django: ["2.2", "3.0", "3.1", "3.2"]
12-
python-version: ["3.6", "3.7", "3.8", "3.9"]
11+
django: ["3.2", "4.0", "4.1"]
12+
python-version: ["3.8", "3.9", "3.10"]
1313
include:
1414
- django: "3.2"
15-
python-version: "3.10"
16-
- django: "4.0"
17-
python-version: "3.10"
18-
- django: "main"
19-
python-version: "3.10"
15+
python-version: "3.7"
16+
- django: "4.1"
17+
python-version: "3.11"
2018
steps:
21-
- uses: actions/checkout@v2
19+
- uses: actions/checkout@v3
2220
- name: Set up Python ${{ matrix.python-version }}
23-
uses: actions/setup-python@v2
21+
uses: actions/setup-python@v4
2422
with:
2523
python-version: ${{ matrix.python-version }}
2624
- name: Install dependencies

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,8 @@ Session.vim
8080
tags
8181
.tox/
8282
.pytest_cache/
83+
84+
# pyenv
85+
# For a library or package, you might want to ignore these files since the code is
86+
# intended to run in multiple environments; otherwise, check them in:
87+
.python-version

.pre-commit-config.yaml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
default_language_version:
2+
python: python3.11
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.4.0
6+
hooks:
7+
- id: check-merge-conflict
8+
- id: check-json
9+
- id: check-yaml
10+
- id: debug-statements
11+
- id: end-of-file-fixer
12+
exclude: ^docs/.*$
13+
- id: pretty-format-json
14+
args:
15+
- --autofix
16+
- id: trailing-whitespace
17+
exclude: README.md
18+
- repo: https://github.com/asottile/pyupgrade
19+
rev: v3.3.2
20+
hooks:
21+
- id: pyupgrade
22+
args: [--py37-plus]
23+
- repo: https://github.com/psf/black
24+
rev: 23.3.0
25+
hooks:
26+
- id: black
27+
- repo: https://github.com/PyCQA/flake8
28+
rev: 6.0.0
29+
hooks:
30+
- id: flake8

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ Then to produce a HTML version of the documentation:
5959

6060
```sh
6161
make html
62-
```
62+
```

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ recursive-include graphene_django/templates *
33
recursive-include graphene_django/static *
44

55
include examples/cookbook/cookbook/ingredients/fixtures/ingredients.json
6-
include examples/cookbook-plain/cookbook/ingredients/fixtures/ingredients.json
6+
include examples/cookbook-plain/cookbook/ingredients/fixtures/ingredients.json

Makefile

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1+
.PHONY: help
2+
help:
3+
@echo "Please use \`make <target>' where <target> is one of"
4+
@grep -E '^\.PHONY: [a-zA-Z_-]+ .*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = "(: |##)"}; {printf "\033[36m%-30s\033[0m %s\n", $$2, $$3}'
5+
16
.PHONY: dev-setup ## Install development dependencies
27
dev-setup:
38
pip install -e ".[dev]"
9+
python -m pre_commit install
410

5-
.PHONY: install-dev
6-
install-dev: dev-setup # Alias install-dev -> dev-setup
7-
8-
.PHONY: tests
11+
.PHONY: tests ## Run unit tests
912
tests:
1013
py.test graphene_django --cov=graphene_django -vv
1114

12-
.PHONY: test
13-
test: tests # Alias test -> tests
14-
15-
.PHONY: format
15+
.PHONY: format ## Format code
1616
format:
17-
black --exclude "/migrations/" graphene_django examples setup.py
17+
black graphene_django examples setup.py
1818

19-
.PHONY: lint
19+
.PHONY: lint ## Lint code
2020
lint:
2121
flake8 graphene_django examples
2222

README.md

+88-61
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# ![Graphene Logo](http://graphene-python.org/favicon.png) Graphene-Django
22

3-
4-
A [Django](https://www.djangoproject.com/) integration for [Graphene](http://graphene-python.org/).
5-
63
[![build][build-image]][build-url]
74
[![pypi][pypi-image]][pypi-url]
85
[![Anaconda-Server Badge][conda-image]][conda-url]
@@ -17,107 +14,137 @@ A [Django](https://www.djangoproject.com/) integration for [Graphene](http://gra
1714
[conda-image]: https://img.shields.io/conda/vn/conda-forge/graphene-django.svg
1815
[conda-url]: https://anaconda.org/conda-forge/graphene-django
1916

20-
[💬 Join the community on Slack](https://join.slack.com/t/graphenetools/shared_invite/enQtOTE2MDQ1NTg4MDM1LTA4Nzk0MGU0NGEwNzUxZGNjNDQ4ZjAwNDJjMjY0OGE1ZDgxZTg4YjM2ZTc4MjE2ZTAzZjE2ZThhZTQzZTkyMmM)
17+
Graphene-Django is an open-source library that provides seamless integration between Django, a high-level Python web framework, and Graphene, a library for building GraphQL APIs. The library allows developers to create GraphQL APIs in Django quickly and efficiently while maintaining a high level of performance.
2118

22-
## Documentation
19+
## Features
2320

24-
[Visit the documentation to get started!](https://docs.graphene-python.org/projects/django/en/latest/)
21+
* Seamless integration with Django models
22+
* Automatic generation of GraphQL schema
23+
* Integration with Django's authentication and permission system
24+
* Easy querying and filtering of data
25+
* Support for Django's pagination system
26+
* Compatible with Django's form and validation system
27+
* Extensive documentation and community support
2528

26-
## Quickstart
29+
## Installation
2730

28-
For installing graphene, just run this command in your shell
31+
To install Graphene-Django, run the following command:
2932

30-
```bash
31-
pip install "graphene-django>=3"
33+
```
34+
pip install graphene-django
3235
```
3336

34-
### Settings
37+
## Configuration
38+
39+
After installation, add 'graphene_django' to your Django project's `INSTALLED_APPS` list and define the GraphQL schema in your project's settings:
3540

3641
```python
37-
INSTALLED_APPS = (
42+
INSTALLED_APPS = [
3843
# ...
39-
'django.contrib.staticfiles', # Required for GraphiQL
4044
'graphene_django',
41-
)
45+
]
4246

4347
GRAPHENE = {
44-
'SCHEMA': 'app.schema.schema' # Where your Graphene schema lives
48+
'SCHEMA': 'myapp.schema.schema'
4549
}
4650
```
4751

48-
### Urls
52+
## Usage
4953

50-
We need to set up a `GraphQL` endpoint in our Django app, so we can serve the queries.
54+
To use Graphene-Django, create a `schema.py` file in your Django app directory and define your GraphQL types and queries:
55+
56+
```python
57+
import graphene
58+
from graphene_django import DjangoObjectType
59+
from .models import MyModel
60+
61+
class MyModelType(DjangoObjectType):
62+
class Meta:
63+
model = MyModel
64+
65+
class Query(graphene.ObjectType):
66+
mymodels = graphene.List(MyModelType)
67+
68+
def resolve_mymodels(self, info, **kwargs):
69+
return MyModel.objects.all()
70+
71+
schema = graphene.Schema(query=Query)
72+
```
73+
74+
Then, expose the GraphQL API in your Django project's `urls.py` file:
5175

5276
```python
5377
from django.urls import path
5478
from graphene_django.views import GraphQLView
79+
from . import schema
5580

5681
urlpatterns = [
5782
# ...
58-
path('graphql/', GraphQLView.as_view(graphiql=True)),
83+
path('graphql/', GraphQLView.as_view(graphiql=True)), # Given that schema path is defined in GRAPHENE['SCHEMA'] in your settings.py
5984
]
6085
```
6186

62-
## Examples
87+
## Testing
6388

64-
Here is a simple Django model:
89+
Graphene-Django provides support for testing GraphQL APIs using Django's test client. To create tests, create a `tests.py` file in your Django app directory and write your test cases:
6590

6691
```python
67-
from django.db import models
68-
69-
class UserModel(models.Model):
70-
name = models.CharField(max_length=100)
71-
last_name = models.CharField(max_length=100)
92+
from django.test import TestCase
93+
from graphene_django.utils.testing import GraphQLTestCase
94+
from . import schema
95+
96+
class MyModelAPITestCase(GraphQLTestCase):
97+
GRAPHENE_SCHEMA = schema.schema
98+
99+
def test_query_all_mymodels(self):
100+
response = self.query(
101+
'''
102+
query {
103+
mymodels {
104+
id
105+
name
106+
}
107+
}
108+
'''
109+
)
110+
111+
self.assertResponseNoErrors(response)
112+
self.assertEqual(len(response.data['mymodels']), MyModel.objects.count())
72113
```
73114

74-
To create a GraphQL schema for it you simply have to write the following:
75-
76-
```python
77-
from graphene_django import DjangoObjectType
78-
import graphene
79-
80-
class User(DjangoObjectType):
81-
class Meta:
82-
model = UserModel
83-
84-
class Query(graphene.ObjectType):
85-
users = graphene.List(User)
115+
## Contributing
86116

87-
def resolve_users(self, info):
88-
return UserModel.objects.all()
117+
Contributions to Graphene-Django are always welcome! To get started, check the repository's [issue tracker](https://github.com/graphql-python/graphene-django/issues) and [contribution guidelines](https://github.com/graphql-python/graphene-django/blob/master/CONTRIBUTING.md).
89118

90-
schema = graphene.Schema(query=Query)
91-
```
119+
## License
92120

93-
Then you can query the schema:
121+
Graphene-Django is released under the [MIT License](https://github.com/graphql-python/graphene-django/blob/master/LICENSE).
94122

95-
```python
96-
query = '''
97-
query {
98-
users {
99-
name,
100-
lastName
101-
}
102-
}
103-
'''
104-
result = schema.execute(query)
105-
```
123+
## Resources
106124

107-
To learn more check out the following [examples](examples/):
125+
* [Official GitHub Repository](https://github.com/graphql-python/graphene-django)
126+
* [Graphene Documentation](http://docs.graphene-python.org/en/latest/)
127+
* [Django Documentation](https://docs.djangoproject.com/en/stable/)
128+
* [GraphQL Specification](https://spec.graphql.org/)
129+
* [GraphiQL](https://github.com/graphql/graphiql) - An in-browser IDE for exploring GraphQL APIs
130+
* [Graphene-Django Community](https://spectrum.chat/graphene) - Join the community to discuss questions and share ideas related to Graphene-Django
108131

109-
* **Schema with Filtering**: [Cookbook example](examples/cookbook)
110-
* **Relay Schema**: [Starwars Relay example](examples/starwars)
132+
## Tutorials and Examples
111133

134+
* [Official Graphene-Django Tutorial](https://docs.graphene-python.org/projects/django/en/latest/tutorial-plain/)
135+
* [Building a GraphQL API with Django and Graphene-Django](https://www.howtographql.com/graphql-python/0-introduction/)
136+
* [Real-world example: Django, Graphene, and Relay](https://github.com/graphql-python/swapi-graphene)
112137

113-
## GraphQL testing clients
114-
- [Firecamp](https://firecamp.io/graphql)
115-
- [GraphiQL](https://github.com/graphql/graphiql)
138+
## Related Projects
116139

140+
* [Graphene](https://github.com/graphql-python/graphene) - A library for building GraphQL APIs in Python
141+
* [Graphene-SQLAlchemy](https://github.com/graphql-python/graphene-sqlalchemy) - Integration between Graphene and SQLAlchemy, an Object Relational Mapper (ORM) for Python
142+
* [Graphene-File-Upload](https://github.com/lmcgartland/graphene-file-upload) - A package providing an Upload scalar for handling file uploads in Graphene
143+
* [Graphene-Subscriptions](https://github.com/graphql-python/graphene-subscriptions) - A package for adding real-time subscriptions to Graphene-based GraphQL APIs
117144

118-
## Contributing
145+
## Support
119146

120-
See [CONTRIBUTING.md](CONTRIBUTING.md)
147+
If you encounter any issues or have questions regarding Graphene-Django, feel free to [submit an issue](https://github.com/graphql-python/graphene-django/issues/new) on the official GitHub repository. You can also ask for help and share your experiences with the Graphene-Django community on [💬 Discord](https://discord.gg/Fftt273T79)
121148

122149
## Release Notes
123150

0 commit comments

Comments
 (0)