Skip to content

Commit 5f6311c

Browse files
authored
Merge branch 'main' into feature/django-forms-inputobjecttype
2 parents ab6c1bf + 0beb338 commit 5f6311c

File tree

83 files changed

+1602
-431
lines changed

Some content is hidden

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

83 files changed

+1602
-431
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 3 additions & 3 deletions
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/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@ 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"
2016
steps:
2117
- uses: actions/checkout@v2
2218
- name: Set up Python ${{ matrix.python-version }}

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
default_language_version:
2+
python: python3.9
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.3.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.2.0
20+
hooks:
21+
- id: pyupgrade
22+
args: [--py37-plus]
23+
- repo: https://github.com/psf/black
24+
rev: 22.10.0
25+
hooks:
26+
- id: black
27+
- repo: https://github.com/PyCQA/flake8
28+
rev: 5.0.4
29+
hooks:
30+
- id: flake8

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
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]"
49

5-
.PHONY: install-dev
6-
install-dev: dev-setup # Alias install-dev -> dev-setup
7-
8-
.PHONY: tests
10+
.PHONY: tests ## Run unit tests
911
tests:
1012
py.test graphene_django --cov=graphene_django -vv
1113

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

19-
.PHONY: lint
18+
.PHONY: lint ## Lint code
2019
lint:
2120
flake8 graphene_django examples
2221

docs/queries.rst

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ For example the following ``Model`` and ``DjangoObjectType``:
151151
152152
Results in the following GraphQL schema definition:
153153

154-
.. code::
154+
.. code:: graphql
155155
156156
type Pet {
157157
id: ID!
@@ -178,7 +178,7 @@ You can disable this automatic conversion by setting
178178
fields = ("id", "kind",)
179179
convert_choices_to_enum = False
180180
181-
.. code::
181+
.. code:: graphql
182182
183183
type Pet {
184184
id: ID!
@@ -313,7 +313,7 @@ Additionally, Resolvers will receive **any arguments declared in the field defin
313313
bar=graphene.Int()
314314
)
315315
316-
def resolve_question(root, info, foo, bar):
316+
def resolve_question(root, info, foo=None, bar=None):
317317
# If `foo` or `bar` are declared in the GraphQL query they will be here, else None.
318318
return Question.objects.filter(foo=foo, bar=bar).first()
319319
@@ -336,12 +336,12 @@ of Django's ``HTTPRequest`` in your resolve methods, such as checking for authen
336336
class Query(graphene.ObjectType):
337337
questions = graphene.List(QuestionType)
338338
339-
def resolve_questions(root, info):
340-
# See if a user is authenticated
341-
if info.context.user.is_authenticated():
342-
return Question.objects.all()
343-
else:
344-
return Question.objects.none()
339+
def resolve_questions(root, info):
340+
# See if a user is authenticated
341+
if info.context.user.is_authenticated():
342+
return Question.objects.all()
343+
else:
344+
return Question.objects.none()
345345
346346
347347
DjangoObjectTypes
@@ -418,29 +418,29 @@ the core graphene pages for more information on customizing the Relay experience
418418
You can now execute queries like:
419419

420420

421-
.. code:: python
421+
.. code:: graphql
422422
423423
{
424424
questions (first: 2, after: "YXJyYXljb25uZWN0aW9uOjEwNQ==") {
425425
pageInfo {
426-
startCursor
427-
endCursor
428-
hasNextPage
429-
hasPreviousPage
426+
startCursor
427+
endCursor
428+
hasNextPage
429+
hasPreviousPage
430430
}
431431
edges {
432-
cursor
433-
node {
434-
id
435-
question_text
436-
}
432+
cursor
433+
node {
434+
id
435+
question_text
436+
}
437437
}
438438
}
439439
}
440440
441441
Which returns:
442442

443-
.. code:: python
443+
.. code:: json
444444
445445
{
446446
"data": {

docs/schema.py

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,57 @@
1-
import graphene
1+
import graphene
22

3-
from graphene_django.types import DjangoObjectType
3+
from graphene_django.types import DjangoObjectType
44

5-
from cookbook.ingredients.models import Category, Ingredient
5+
from cookbook.ingredients.models import Category, Ingredient
66

77

8-
class CategoryType(DjangoObjectType):
9-
class Meta:
10-
model = Category
11-
fields = '__all__'
8+
class CategoryType(DjangoObjectType):
9+
class Meta:
10+
model = Category
11+
fields = "__all__"
1212

1313

14-
class IngredientType(DjangoObjectType):
15-
class Meta:
16-
model = Ingredient
17-
fields = '__all__'
14+
class IngredientType(DjangoObjectType):
15+
class Meta:
16+
model = Ingredient
17+
fields = "__all__"
1818

1919

20-
class Query(object):
21-
category = graphene.Field(CategoryType,
22-
id=graphene.Int(),
23-
name=graphene.String())
24-
all_categories = graphene.List(CategoryType)
20+
class Query:
21+
category = graphene.Field(CategoryType, id=graphene.Int(), name=graphene.String())
22+
all_categories = graphene.List(CategoryType)
2523

24+
ingredient = graphene.Field(
25+
IngredientType, id=graphene.Int(), name=graphene.String()
26+
)
27+
all_ingredients = graphene.List(IngredientType)
2628

27-
ingredient = graphene.Field(IngredientType,
28-
id=graphene.Int(),
29-
name=graphene.String())
30-
all_ingredients = graphene.List(IngredientType)
29+
def resolve_all_categories(self, info, **kwargs):
30+
return Category.objects.all()
3131

32-
def resolve_all_categories(self, info, **kwargs):
33-
return Category.objects.all()
32+
def resolve_all_ingredients(self, info, **kwargs):
33+
return Ingredient.objects.all()
3434

35-
def resolve_all_ingredients(self, info, **kwargs):
36-
return Ingredient.objects.all()
35+
def resolve_category(self, info, **kwargs):
36+
id = kwargs.get("id")
37+
name = kwargs.get("name")
3738

38-
def resolve_category(self, info, **kwargs):
39-
id = kwargs.get('id')
40-
name = kwargs.get('name')
39+
if id is not None:
40+
return Category.objects.get(pk=id)
4141

42-
if id is not None:
43-
return Category.objects.get(pk=id)
42+
if name is not None:
43+
return Category.objects.get(name=name)
4444

45-
if name is not None:
46-
return Category.objects.get(name=name)
45+
return None
4746

48-
return None
47+
def resolve_ingredient(self, info, **kwargs):
48+
id = kwargs.get("id")
49+
name = kwargs.get("name")
4950

50-
def resolve_ingredient(self, info, **kwargs):
51-
id = kwargs.get('id')
52-
name = kwargs.get('name')
51+
if id is not None:
52+
return Ingredient.objects.get(pk=id)
5353

54-
if id is not None:
55-
return Ingredient.objects.get(pk=id)
54+
if name is not None:
55+
return Ingredient.objects.get(name=name)
5656

57-
if name is not None:
58-
return Ingredient.objects.get(name=name)
59-
60-
return None
57+
return None

docs/settings.rst

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Default: ``None``
189189
190190
191191
``GRAPHIQL_HEADER_EDITOR_ENABLED``
192-
---------------------
192+
----------------------------------
193193

194194
GraphiQL starting from version 1.0.0 allows setting custom headers in similar fashion to query variables.
195195

@@ -207,3 +207,36 @@ Default: ``True``
207207
GRAPHENE = {
208208
'GRAPHIQL_HEADER_EDITOR_ENABLED': True,
209209
}
210+
211+
212+
``TESTING_ENDPOINT``
213+
--------------------
214+
215+
Define the graphql endpoint url used for the `GraphQLTestCase` class.
216+
217+
Default: ``/graphql``
218+
219+
.. code:: python
220+
221+
GRAPHENE = {
222+
'TESTING_ENDPOINT': '/customEndpoint'
223+
}
224+
225+
226+
``GRAPHIQL_SHOULD_PERSIST_HEADERS``
227+
---------------------
228+
229+
Set to ``True`` if you want to persist GraphiQL headers after refreshing the page.
230+
231+
This setting is passed to ``shouldPersistHeaders`` GraphiQL options, for details refer to GraphiQLDocs_.
232+
233+
.. _GraphiQLDocs: https://github.com/graphql/graphiql/tree/main/packages/graphiql#options
234+
235+
236+
Default: ``False``
237+
238+
.. code:: python
239+
240+
GRAPHENE = {
241+
'GRAPHIQL_SHOULD_PERSIST_HEADERS': False,
242+
}

docs/testing.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Using unittest
66

77
If you want to unittest your API calls derive your test case from the class `GraphQLTestCase`.
88

9-
Your endpoint is set through the `GRAPHQL_URL` attribute on `GraphQLTestCase`. The default endpoint is `GRAPHQL_URL = "/graphql/"`.
9+
The default endpoint for testing is `/graphql`. You can override this in the `settings <https://docs.graphene-python.org/projects/django/en/latest/settings/#testing-endpoint>`__.
10+
1011

1112
Usage:
1213

docs/tutorial-plain.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Now sync your database for the first time:
3535

3636
.. code:: bash
3737
38+
cd ..
3839
python manage.py migrate
3940
4041
Let's create a few simple models...
@@ -77,6 +78,18 @@ Add ingredients as INSTALLED_APPS:
7778
"cookbook.ingredients",
7879
]
7980
81+
Make sure the app name in ``cookbook.ingredients.apps.IngredientsConfig`` is set to ``cookbook.ingredients``.
82+
83+
.. code:: python
84+
85+
# cookbook/ingredients/apps.py
86+
87+
from django.apps import AppConfig
88+
89+
90+
class IngredientsConfig(AppConfig):
91+
default_auto_field = 'django.db.models.BigAutoField'
92+
name = 'cookbook.ingredients'
8093
8194
Don't forget to create & run migrations:
8295

docs/tutorial-relay.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Create ``cookbook/ingredients/schema.py`` and type the following:
151151
interfaces = (relay.Node, )
152152
153153
154-
class Query(graphene.ObjectType):
154+
class Query(ObjectType):
155155
category = relay.Node.Field(CategoryNode)
156156
all_categories = DjangoFilterConnectionField(CategoryNode)
157157

0 commit comments

Comments
 (0)