mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-03 20:03:30 +03:00
Merge branch 'master' into issue-#1009_fix_backward_relay_pagination
This commit is contained in:
commit
d11117ff06
|
@ -1,3 +1,6 @@
|
||||||
include README.md LICENSE
|
include README.md LICENSE
|
||||||
recursive-include graphene_django/templates *
|
recursive-include graphene_django/templates *
|
||||||
recursive-include graphene_django/static *
|
recursive-include graphene_django/static *
|
||||||
|
|
||||||
|
include examples/cookbook/cookbook/ingredients/fixtures/ingredients.json
|
||||||
|
include examples/cookbook-plain/cookbook/ingredients/fixtures/ingredients.json
|
|
@ -1,35 +0,0 @@
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
|
|
||||||
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
sys.path.insert(0, ROOT_PATH + '/examples/')
|
|
||||||
|
|
||||||
SECRET_KEY = 1
|
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
|
||||||
'graphene_django',
|
|
||||||
'graphene_django.rest_framework',
|
|
||||||
'graphene_django.tests',
|
|
||||||
'starwars',
|
|
||||||
]
|
|
||||||
|
|
||||||
DATABASES = {
|
|
||||||
'default': {
|
|
||||||
'ENGINE': 'django.db.backends.sqlite3',
|
|
||||||
'NAME': 'django_test.sqlite',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TEMPLATES = [
|
|
||||||
{
|
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
||||||
'DIRS': [],
|
|
||||||
'APP_DIRS': True,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
GRAPHENE = {
|
|
||||||
'SCHEMA': 'graphene_django.tests.schema_view.schema'
|
|
||||||
}
|
|
||||||
|
|
||||||
ROOT_URLCONF = 'graphene_django.tests.urls'
|
|
0
examples/__init__.py
Normal file
0
examples/__init__.py
Normal file
0
examples/cookbook-plain/__init__.py
Normal file
0
examples/cookbook-plain/__init__.py
Normal file
0
examples/cookbook/__init__.py
Normal file
0
examples/cookbook/__init__.py
Normal file
30
examples/django_test_settings.py
Normal file
30
examples/django_test_settings.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
sys.path.insert(0, ROOT_PATH + "/examples/")
|
||||||
|
|
||||||
|
SECRET_KEY = 1
|
||||||
|
|
||||||
|
INSTALLED_APPS = [
|
||||||
|
"graphene_django",
|
||||||
|
"graphene_django.rest_framework",
|
||||||
|
"graphene_django.tests",
|
||||||
|
"examples.starwars",
|
||||||
|
]
|
||||||
|
|
||||||
|
DATABASES = {
|
||||||
|
"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": "django_test.sqlite"}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEMPLATES = [
|
||||||
|
{
|
||||||
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||||
|
"DIRS": [],
|
||||||
|
"APP_DIRS": True,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
GRAPHENE = {"SCHEMA": "graphene_django.tests.schema_view.schema"}
|
||||||
|
|
||||||
|
ROOT_URLCONF = "graphene_django.tests.urls"
|
|
@ -26,6 +26,7 @@ def fields_for_serializer(
|
||||||
exclude_fields,
|
exclude_fields,
|
||||||
is_input=False,
|
is_input=False,
|
||||||
convert_choices_to_enum=True,
|
convert_choices_to_enum=True,
|
||||||
|
lookup_field=None,
|
||||||
):
|
):
|
||||||
fields = OrderedDict()
|
fields = OrderedDict()
|
||||||
for name, field in serializer.fields.items():
|
for name, field in serializer.fields.items():
|
||||||
|
@ -35,7 +36,9 @@ def fields_for_serializer(
|
||||||
name in exclude_fields,
|
name in exclude_fields,
|
||||||
field.write_only
|
field.write_only
|
||||||
and not is_input, # don't show write_only fields in Query
|
and not is_input, # don't show write_only fields in Query
|
||||||
field.read_only and is_input, # don't show read_only fields in Input
|
field.read_only
|
||||||
|
and is_input
|
||||||
|
and lookup_field != name, # don't show read_only fields in Input
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -91,6 +94,7 @@ class SerializerMutation(ClientIDMutation):
|
||||||
exclude_fields,
|
exclude_fields,
|
||||||
is_input=True,
|
is_input=True,
|
||||||
convert_choices_to_enum=convert_choices_to_enum,
|
convert_choices_to_enum=convert_choices_to_enum,
|
||||||
|
lookup_field=lookup_field,
|
||||||
)
|
)
|
||||||
output_fields = fields_for_serializer(
|
output_fields = fields_for_serializer(
|
||||||
serializer,
|
serializer,
|
||||||
|
@ -98,6 +102,7 @@ class SerializerMutation(ClientIDMutation):
|
||||||
exclude_fields,
|
exclude_fields,
|
||||||
is_input=False,
|
is_input=False,
|
||||||
convert_choices_to_enum=convert_choices_to_enum,
|
convert_choices_to_enum=convert_choices_to_enum,
|
||||||
|
lookup_field=lookup_field,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not _meta:
|
if not _meta:
|
||||||
|
|
|
@ -143,17 +143,20 @@ def test_write_only_field_using_extra_kwargs():
|
||||||
|
|
||||||
def test_read_only_fields():
|
def test_read_only_fields():
|
||||||
class ReadOnlyFieldModelSerializer(serializers.ModelSerializer):
|
class ReadOnlyFieldModelSerializer(serializers.ModelSerializer):
|
||||||
|
id = serializers.CharField(read_only=True)
|
||||||
cool_name = serializers.CharField(read_only=True)
|
cool_name = serializers.CharField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = MyFakeModelWithPassword
|
model = MyFakeModelWithPassword
|
||||||
fields = ["cool_name", "password"]
|
lookup_field = "id"
|
||||||
|
fields = ["id", "cool_name", "password"]
|
||||||
|
|
||||||
class MyMutation(SerializerMutation):
|
class MyMutation(SerializerMutation):
|
||||||
class Meta:
|
class Meta:
|
||||||
serializer_class = ReadOnlyFieldModelSerializer
|
serializer_class = ReadOnlyFieldModelSerializer
|
||||||
|
|
||||||
assert "password" in MyMutation.Input._meta.fields
|
assert "password" in MyMutation.Input._meta.fields
|
||||||
|
assert "id" in MyMutation.Input._meta.fields
|
||||||
assert (
|
assert (
|
||||||
"cool_name" not in MyMutation.Input._meta.fields
|
"cool_name" not in MyMutation.Input._meta.fields
|
||||||
), "'cool_name' is read_only field and shouldn't be on arguments"
|
), "'cool_name' is read_only field and shouldn't be on arguments"
|
||||||
|
|
|
@ -267,7 +267,7 @@ class TestDjangoListField:
|
||||||
result = schema.execute(query)
|
result = schema.execute(query)
|
||||||
|
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {"reporters": [{"firstName": "Tara"},]}
|
assert result.data == {"reporters": [{"firstName": "Tara"}]}
|
||||||
|
|
||||||
def test_resolve_list(self):
|
def test_resolve_list(self):
|
||||||
"""Resolving a plain list should work (and not call get_queryset)"""
|
"""Resolving a plain list should work (and not call get_queryset)"""
|
||||||
|
@ -314,7 +314,7 @@ class TestDjangoListField:
|
||||||
result = schema.execute(query)
|
result = schema.execute(query)
|
||||||
|
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {"reporters": [{"firstName": "Debra"},]}
|
assert result.data == {"reporters": [{"firstName": "Debra"}]}
|
||||||
|
|
||||||
def test_get_queryset_foreign_key(self):
|
def test_get_queryset_foreign_key(self):
|
||||||
class Article(DjangoObjectType):
|
class Article(DjangoObjectType):
|
||||||
|
@ -371,7 +371,7 @@ class TestDjangoListField:
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == {
|
assert result.data == {
|
||||||
"reporters": [
|
"reporters": [
|
||||||
{"firstName": "Tara", "articles": [{"headline": "Amazing news"},],},
|
{"firstName": "Tara", "articles": [{"headline": "Amazing news"}]},
|
||||||
{"firstName": "Debra", "articles": []},
|
{"firstName": "Debra", "articles": []},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
[pytest]
|
[pytest]
|
||||||
DJANGO_SETTINGS_MODULE = django_test_settings
|
DJANGO_SETTINGS_MODULE = examples.django_test_settings
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -58,7 +58,7 @@ setup(
|
||||||
"Framework :: Django :: 3.0",
|
"Framework :: Django :: 3.0",
|
||||||
],
|
],
|
||||||
keywords="api graphql protocol rest relay graphene",
|
keywords="api graphql protocol rest relay graphene",
|
||||||
packages=find_packages(exclude=["tests"]),
|
packages=find_packages(exclude=["tests", "examples", "examples.*"]),
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"six>=1.10.0",
|
"six>=1.10.0",
|
||||||
"graphene>=2.1.7,<3",
|
"graphene>=2.1.7,<3",
|
||||||
|
|
3
tox.ini
3
tox.ini
|
@ -25,11 +25,12 @@ DJANGO =
|
||||||
passenv = *
|
passenv = *
|
||||||
usedevelop = True
|
usedevelop = True
|
||||||
setenv =
|
setenv =
|
||||||
DJANGO_SETTINGS_MODULE=django_test_settings
|
DJANGO_SETTINGS_MODULE=examples.django_test_settings
|
||||||
deps =
|
deps =
|
||||||
-e.[test]
|
-e.[test]
|
||||||
psycopg2-binary
|
psycopg2-binary
|
||||||
django111: Django>=1.11,<2.0
|
django111: Django>=1.11,<2.0
|
||||||
|
django111: djangorestframework<3.12
|
||||||
django20: Django>=2.0,<2.1
|
django20: Django>=2.0,<2.1
|
||||||
django21: Django>=2.1,<2.2
|
django21: Django>=2.1,<2.2
|
||||||
django22: Django>=2.2,<3.0
|
django22: Django>=2.2,<3.0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user