mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-02-22 06:20:33 +03:00
resolve conflicts and fix format
This commit is contained in:
parent
2ae927f06a
commit
28bc858444
|
@ -2,8 +2,7 @@ import asyncio
|
||||||
|
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
|
|
||||||
from cookbook.recipes.models import Recipe, RecipeIngredient
|
from graphene import Field, Node, String
|
||||||
from graphene import Node, String, Field
|
|
||||||
from graphene_django.filter import DjangoFilterConnectionField
|
from graphene_django.filter import DjangoFilterConnectionField
|
||||||
from graphene_django.types import DjangoObjectType
|
from graphene_django.types import DjangoObjectType
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from django.urls import re_path
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from django.urls import re_path
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
|
||||||
from graphene_django.views import AsyncGraphQLView
|
from graphene_django.views import AsyncGraphQLView
|
||||||
from graphene_django.views import GraphQLView
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
re_path(r"^admin/", admin.site.urls),
|
re_path(r"^admin/", admin.site.urls),
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
from django.db import connections
|
|
||||||
|
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
import inspect
|
from django.db import connections
|
||||||
from .sql.tracking import unwrap_cursor, wrap_cursor
|
|
||||||
from .exception.formating import wrap_exception
|
|
||||||
from .types import DjangoDebug
|
|
||||||
from graphql.type.definition import GraphQLNonNull
|
from graphql.type.definition import GraphQLNonNull
|
||||||
|
|
||||||
from django.db.models import QuerySet
|
|
||||||
|
|
||||||
from ..utils import is_sync_function
|
from ..utils import is_sync_function
|
||||||
|
from .exception.formating import wrap_exception
|
||||||
|
from .sql.tracking import unwrap_cursor, wrap_cursor
|
||||||
|
from .types import DjangoDebug
|
||||||
|
|
||||||
|
|
||||||
class DjangoDebugContext:
|
class DjangoDebugContext:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import inspect
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
from asgiref.sync import sync_to_async
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
from graphql_relay import (
|
from graphql_relay import (
|
||||||
connection_from_array_slice,
|
connection_from_array_slice,
|
||||||
|
@ -9,16 +9,13 @@ from graphql_relay import (
|
||||||
offset_to_cursor,
|
offset_to_cursor,
|
||||||
)
|
)
|
||||||
|
|
||||||
from asgiref.sync import sync_to_async
|
|
||||||
from promise import Promise
|
|
||||||
|
|
||||||
from graphene import Int, NonNull
|
from graphene import Int, NonNull
|
||||||
from graphene.relay import ConnectionField
|
from graphene.relay import ConnectionField
|
||||||
from graphene.relay.connection import connection_adapter, page_info_adapter
|
from graphene.relay.connection import connection_adapter, page_info_adapter
|
||||||
from graphene.types import Field, List
|
from graphene.types import Field, List
|
||||||
|
|
||||||
from .settings import graphene_settings
|
from .settings import graphene_settings
|
||||||
from .utils import maybe_queryset, is_sync_function, is_running_async
|
from .utils import is_running_async, is_sync_function, maybe_queryset
|
||||||
|
|
||||||
|
|
||||||
class DjangoListField(Field):
|
class DjangoListField(Field):
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
from asgiref.sync import sync_to_async
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
|
||||||
from graphene.types.argument import to_arguments
|
from graphene.types.argument import to_arguments
|
||||||
from graphene.types.enum import EnumType
|
from graphene.types.enum import EnumType
|
||||||
from graphene.utils.str_converters import to_snake_case
|
from graphene.utils.str_converters import to_snake_case
|
||||||
|
|
||||||
from asgiref.sync import sync_to_async
|
|
||||||
|
|
||||||
from ..fields import DjangoConnectionField
|
from ..fields import DjangoConnectionField
|
||||||
from .utils import get_filtering_args_from_filterset, get_filterset_class
|
from .utils import get_filtering_args_from_filterset, get_filterset_class
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
|
||||||
|
from asgiref.sync import sync_to_async
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
from asgiref.sync import sync_to_async
|
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
from graphene.relay.mutation import ClientIDMutation
|
from graphene.relay.mutation import ClientIDMutation
|
||||||
|
@ -12,8 +12,8 @@ from graphene.types.mutation import MutationOptions
|
||||||
from graphene.types.objecttype import yank_fields_from_attrs
|
from graphene.types.objecttype import yank_fields_from_attrs
|
||||||
|
|
||||||
from ..types import ErrorType
|
from ..types import ErrorType
|
||||||
from .serializer_converter import convert_serializer_field
|
|
||||||
from ..utils import is_running_async
|
from ..utils import is_running_async
|
||||||
|
from .serializer_converter import convert_serializer_field
|
||||||
|
|
||||||
|
|
||||||
class SerializerMutationOptions(MutationOptions):
|
class SerializerMutationOptions(MutationOptions):
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
from django.db.models import Count, Prefetch
|
|
||||||
from asgiref.sync import sync_to_async, async_to_sync
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from asgiref.sync import async_to_sync
|
||||||
from django.db.models import Count, Prefetch
|
from django.db.models import Count, Prefetch
|
||||||
|
|
||||||
from graphene import List, NonNull, ObjectType, Schema, String
|
from graphene import List, NonNull, ObjectType, Schema, String
|
||||||
|
|
||||||
from ..fields import DjangoListField
|
from ..fields import DjangoListField
|
||||||
from ..types import DjangoObjectType
|
from ..types import DjangoObjectType
|
||||||
|
from .async_test_helper import assert_async_result_equal
|
||||||
from .models import (
|
from .models import (
|
||||||
Article as ArticleModel,
|
Article as ArticleModel,
|
||||||
Film as FilmModel,
|
Film as FilmModel,
|
||||||
FilmDetails as FilmDetailsModel,
|
FilmDetails as FilmDetailsModel,
|
||||||
Reporter as ReporterModel,
|
Reporter as ReporterModel,
|
||||||
)
|
)
|
||||||
from .async_test_helper import assert_async_result_equal
|
|
||||||
|
|
||||||
|
|
||||||
class TestDjangoListField:
|
class TestDjangoListField:
|
||||||
|
|
|
@ -2,12 +2,12 @@ import base64
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from asgiref.sync import async_to_sync
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.utils.functional import SimpleLazyObject
|
from django.utils.functional import SimpleLazyObject
|
||||||
from graphql_relay import to_global_id
|
from graphql_relay import to_global_id
|
||||||
from pytest import raises
|
from pytest import raises
|
||||||
from asgiref.sync import sync_to_async, async_to_sync
|
|
||||||
|
|
||||||
import graphene
|
import graphene
|
||||||
from graphene.relay import Node
|
from graphene.relay import Node
|
||||||
|
@ -28,6 +28,7 @@ from .models import (
|
||||||
Reporter,
|
Reporter,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_should_query_only_fields():
|
def test_should_query_only_fields():
|
||||||
with raises(Exception):
|
with raises(Exception):
|
||||||
|
|
||||||
|
@ -1569,7 +1570,7 @@ def test_connection_should_limit_after_to_list_length():
|
||||||
expected = {"allReporters": {"edges": []}}
|
expected = {"allReporters": {"edges": []}}
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
assert_async_result_equal(schema, query, result, variable_values=dict(after=after))
|
assert_async_result_equal(schema, query, result, variable_values={"after": after})
|
||||||
|
|
||||||
|
|
||||||
REPORTERS = [
|
REPORTERS = [
|
||||||
|
@ -1667,7 +1668,7 @@ def test_should_have_next_page(graphene_settings):
|
||||||
gql_reporter["node"]["id"] for gql_reporter in gql_reporters
|
gql_reporter["node"]["id"] for gql_reporter in gql_reporters
|
||||||
}
|
}
|
||||||
assert_async_result_equal(
|
assert_async_result_equal(
|
||||||
schema, query, result2, variable_values=dict(first=4, after=last_result)
|
schema, query, result2, variable_values={"first": 4, "after": last_result}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1736,7 +1737,7 @@ class TestBackwardPagination:
|
||||||
|
|
||||||
def test_query_first_last_and_after(self, graphene_settings, max_limit):
|
def test_query_first_last_and_after(self, graphene_settings, max_limit):
|
||||||
schema = self.setup_schema(graphene_settings, max_limit=max_limit)
|
schema = self.setup_schema(graphene_settings, max_limit=max_limit)
|
||||||
query = """
|
query_first_last_and_after = """
|
||||||
query queryAfter($after: String) {
|
query queryAfter($after: String) {
|
||||||
allReporters(first: 4, last: 3, after: $after) {
|
allReporters(first: 4, last: 3, after: $after) {
|
||||||
edges {
|
edges {
|
||||||
|
@ -1759,12 +1760,12 @@ class TestBackwardPagination:
|
||||||
e["node"]["firstName"] for e in result.data["allReporters"]["edges"]
|
e["node"]["firstName"] for e in result.data["allReporters"]["edges"]
|
||||||
] == ["First 2", "First 3", "First 4"]
|
] == ["First 2", "First 3", "First 4"]
|
||||||
assert_async_result_equal(
|
assert_async_result_equal(
|
||||||
schema, query, result, variable_values=dict(after=after)
|
schema, query_first_last_and_after, result, variable_values={"after": after}
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_query_last_and_before(self, graphene_settings, max_limit):
|
def test_query_last_and_before(self, graphene_settings, max_limit):
|
||||||
schema = self.setup_schema(graphene_settings, max_limit=max_limit)
|
schema = self.setup_schema(graphene_settings, max_limit=max_limit)
|
||||||
query = """
|
query_first_last_and_after = """
|
||||||
query queryAfter($before: String) {
|
query queryAfter($before: String) {
|
||||||
allReporters(last: 1, before: $before) {
|
allReporters(last: 1, before: $before) {
|
||||||
edges {
|
edges {
|
||||||
|
@ -1777,12 +1778,12 @@ class TestBackwardPagination:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
result = schema.execute(
|
result = schema.execute(
|
||||||
query,
|
query_first_last_and_after,
|
||||||
)
|
)
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
assert len(result.data["allReporters"]["edges"]) == 1
|
assert len(result.data["allReporters"]["edges"]) == 1
|
||||||
assert result.data["allReporters"]["edges"][0]["node"]["firstName"] == "First 5"
|
assert result.data["allReporters"]["edges"][0]["node"]["firstName"] == "First 5"
|
||||||
assert_async_result_equal(schema, query, result)
|
assert_async_result_equal(schema, query_first_last_and_after, result)
|
||||||
|
|
||||||
before = base64.b64encode(b"arrayconnection:5").decode()
|
before = base64.b64encode(b"arrayconnection:5").decode()
|
||||||
result = schema.execute(
|
result = schema.execute(
|
||||||
|
@ -1793,7 +1794,10 @@ class TestBackwardPagination:
|
||||||
assert len(result.data["allReporters"]["edges"]) == 1
|
assert len(result.data["allReporters"]["edges"]) == 1
|
||||||
assert result.data["allReporters"]["edges"][0]["node"]["firstName"] == "First 4"
|
assert result.data["allReporters"]["edges"][0]["node"]["firstName"] == "First 4"
|
||||||
assert_async_result_equal(
|
assert_async_result_equal(
|
||||||
schema, query, result, variable_values=dict(before=before)
|
schema,
|
||||||
|
query_first_last_and_after,
|
||||||
|
result,
|
||||||
|
variable_values={"before": before},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -2021,9 +2025,7 @@ def test_connection_should_forbid_offset_filtering_with_before():
|
||||||
expected_error = "You can't provide a `before` value at the same time as an `offset` value to properly paginate the `allReporters` connection."
|
expected_error = "You can't provide a `before` value at the same time as an `offset` value to properly paginate the `allReporters` connection."
|
||||||
assert len(result.errors) == 1
|
assert len(result.errors) == 1
|
||||||
assert result.errors[0].message == expected_error
|
assert result.errors[0].message == expected_error
|
||||||
assert_async_result_equal(
|
assert_async_result_equal(schema, query, result, variable_values={"before": before})
|
||||||
schema, query, result, variable_values=dict(before=before)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_connection_should_allow_offset_filtering_with_after():
|
def test_connection_should_allow_offset_filtering_with_after():
|
||||||
|
@ -2066,7 +2068,7 @@ def test_connection_should_allow_offset_filtering_with_after():
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
assert_async_result_equal(schema, query, result, variable_values=dict(after=after))
|
assert_async_result_equal(schema, query, result, variable_values={"after": after})
|
||||||
|
|
||||||
|
|
||||||
def test_connection_should_succeed_if_last_higher_than_number_of_objects():
|
def test_connection_should_succeed_if_last_higher_than_number_of_objects():
|
||||||
|
@ -2097,7 +2099,7 @@ def test_connection_should_succeed_if_last_higher_than_number_of_objects():
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
expected = {"allReporters": {"edges": []}}
|
expected = {"allReporters": {"edges": []}}
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
assert_async_result_equal(schema, query, result, variable_values=dict(last=2))
|
assert_async_result_equal(schema, query, result, variable_values={"last": 2})
|
||||||
|
|
||||||
Reporter.objects.create(first_name="John", last_name="Doe")
|
Reporter.objects.create(first_name="John", last_name="Doe")
|
||||||
Reporter.objects.create(first_name="Some", last_name="Guy")
|
Reporter.objects.create(first_name="Some", last_name="Guy")
|
||||||
|
@ -2115,7 +2117,7 @@ def test_connection_should_succeed_if_last_higher_than_number_of_objects():
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
assert_async_result_equal(schema, query, result, variable_values=dict(last=2))
|
assert_async_result_equal(schema, query, result, variable_values={"last": 2})
|
||||||
|
|
||||||
result = schema.execute(query, variable_values={"last": 4})
|
result = schema.execute(query, variable_values={"last": 4})
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
|
@ -2130,7 +2132,7 @@ def test_connection_should_succeed_if_last_higher_than_number_of_objects():
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
assert_async_result_equal(schema, query, result, variable_values=dict(last=4))
|
assert_async_result_equal(schema, query, result, variable_values={"last": 4})
|
||||||
|
|
||||||
result = schema.execute(query, variable_values={"last": 20})
|
result = schema.execute(query, variable_values={"last": 20})
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
|
@ -2145,7 +2147,7 @@ def test_connection_should_succeed_if_last_higher_than_number_of_objects():
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert result.data == expected
|
assert result.data == expected
|
||||||
assert_async_result_equal(schema, query, result, variable_values=dict(last=20))
|
assert_async_result_equal(schema, query, result, variable_values={"last": 20})
|
||||||
|
|
||||||
|
|
||||||
def test_should_query_nullable_foreign_key():
|
def test_should_query_nullable_foreign_key():
|
||||||
|
|
|
@ -16,8 +16,8 @@ from .utils import (
|
||||||
DJANGO_FILTER_INSTALLED,
|
DJANGO_FILTER_INSTALLED,
|
||||||
camelize,
|
camelize,
|
||||||
get_model_fields,
|
get_model_fields,
|
||||||
is_valid_django_model,
|
|
||||||
is_running_async,
|
is_running_async,
|
||||||
|
is_valid_django_model,
|
||||||
)
|
)
|
||||||
|
|
||||||
ALL_FIELDS = "__all__"
|
ALL_FIELDS = "__all__"
|
||||||
|
|
|
@ -5,10 +5,10 @@ from .utils import (
|
||||||
camelize,
|
camelize,
|
||||||
get_model_fields,
|
get_model_fields,
|
||||||
get_reverse_fields,
|
get_reverse_fields,
|
||||||
|
is_running_async,
|
||||||
|
is_sync_function,
|
||||||
is_valid_django_model,
|
is_valid_django_model,
|
||||||
maybe_queryset,
|
maybe_queryset,
|
||||||
is_sync_function,
|
|
||||||
is_running_async,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
|
|
|
@ -153,6 +153,7 @@ def is_sync_function(func):
|
||||||
func
|
func
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def bypass_get_queryset(resolver):
|
def bypass_get_queryset(resolver):
|
||||||
"""
|
"""
|
||||||
Adds a bypass_get_queryset attribute to the resolver, which is used to
|
Adds a bypass_get_queryset attribute to the resolver, which is used to
|
||||||
|
|
|
@ -2,16 +2,14 @@ import inspect
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import traceback
|
import traceback
|
||||||
|
from asyncio import coroutines, gather
|
||||||
from asyncio import gather, coroutines
|
|
||||||
|
|
||||||
from django.db import connection, transaction
|
from django.db import connection, transaction
|
||||||
from django.http import HttpResponse, HttpResponseNotAllowed
|
from django.http import HttpResponse, HttpResponseNotAllowed
|
||||||
from django.http.response import HttpResponseBadRequest
|
from django.http.response import HttpResponseBadRequest
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import classonlymethod, method_decorator
|
||||||
from django.views.decorators.csrf import ensure_csrf_cookie
|
from django.views.decorators.csrf import ensure_csrf_cookie
|
||||||
from django.utils.decorators import classonlymethod
|
|
||||||
from django.views.generic import View
|
from django.views.generic import View
|
||||||
from graphql import OperationType, get_operation_ast, parse
|
from graphql import OperationType, get_operation_ast, parse
|
||||||
from graphql.error import GraphQLError
|
from graphql.error import GraphQLError
|
||||||
|
|
Loading…
Reference in New Issue
Block a user