mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-25 19:14:11 +03:00
Fix duplicated ErrorType declaration (#539)
* Add failing test case * Fix duplicated ErrorType declaration
This commit is contained in:
parent
0a5020bee1
commit
923d8282c7
|
@ -14,7 +14,7 @@ from graphene.types.utils import yank_fields_from_attrs
|
||||||
from graphene_django.registry import get_global_registry
|
from graphene_django.registry import get_global_registry
|
||||||
|
|
||||||
from .converter import convert_form_field
|
from .converter import convert_form_field
|
||||||
from .types import ErrorType
|
from ..types import ErrorType
|
||||||
|
|
||||||
|
|
||||||
def fields_for_form(form, only_fields, exclude_fields):
|
def fields_for_form(form, only_fields, exclude_fields):
|
||||||
|
|
|
@ -9,7 +9,7 @@ from graphene.relay.mutation import ClientIDMutation
|
||||||
from graphene.types.objecttype import yank_fields_from_attrs
|
from graphene.types.objecttype import yank_fields_from_attrs
|
||||||
|
|
||||||
from .serializer_converter import convert_serializer_field
|
from .serializer_converter import convert_serializer_field
|
||||||
from .types import ErrorType
|
from ..types import ErrorType
|
||||||
|
|
||||||
|
|
||||||
class SerializerMutationOptions(MutationOptions):
|
class SerializerMutationOptions(MutationOptions):
|
||||||
|
|
|
@ -2,11 +2,6 @@ import graphene
|
||||||
from graphene.types.unmountedtype import UnmountedType
|
from graphene.types.unmountedtype import UnmountedType
|
||||||
|
|
||||||
|
|
||||||
class ErrorType(graphene.ObjectType):
|
|
||||||
field = graphene.String(required=True)
|
|
||||||
messages = graphene.List(graphene.NonNull(graphene.String), required=True)
|
|
||||||
|
|
||||||
|
|
||||||
class DictType(UnmountedType):
|
class DictType(UnmountedType):
|
||||||
key = graphene.String()
|
key = graphene.String()
|
||||||
value = graphene.String()
|
value = graphene.String()
|
||||||
|
|
0
graphene_django/tests/issues/__init__.py
Normal file
0
graphene_django/tests/issues/__init__.py
Normal file
44
graphene_django/tests/issues/test_520.py
Normal file
44
graphene_django/tests/issues/test_520.py
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
# https://github.com/graphql-python/graphene-django/issues/520
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
from django import forms
|
||||||
|
|
||||||
|
import graphene
|
||||||
|
|
||||||
|
from graphene import Field, ResolveInfo
|
||||||
|
from graphene.types.inputobjecttype import InputObjectType
|
||||||
|
from py.test import raises
|
||||||
|
from py.test import mark
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from ...types import DjangoObjectType
|
||||||
|
from ...rest_framework.models import MyFakeModel
|
||||||
|
from ...rest_framework.mutation import SerializerMutation
|
||||||
|
from ...forms.mutation import DjangoFormMutation
|
||||||
|
|
||||||
|
|
||||||
|
class MyModelSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = MyFakeModel
|
||||||
|
fields = "__all__"
|
||||||
|
|
||||||
|
|
||||||
|
class MyForm(forms.Form):
|
||||||
|
text = forms.CharField()
|
||||||
|
|
||||||
|
|
||||||
|
def test_can_use_form_and_serializer_mutations():
|
||||||
|
class MyMutation(SerializerMutation):
|
||||||
|
class Meta:
|
||||||
|
serializer_class = MyModelSerializer
|
||||||
|
|
||||||
|
class MyFormMutation(DjangoFormMutation):
|
||||||
|
class Meta:
|
||||||
|
form_class = MyForm
|
||||||
|
|
||||||
|
class Mutation(graphene.ObjectType):
|
||||||
|
my_mutation = MyMutation.Field()
|
||||||
|
my_form_mutation = MyFormMutation.Field()
|
||||||
|
|
||||||
|
graphene.Schema(mutation=Mutation)
|
|
@ -3,6 +3,7 @@ from collections import OrderedDict
|
||||||
|
|
||||||
from django.db.models import Model
|
from django.db.models import Model
|
||||||
from django.utils.functional import SimpleLazyObject
|
from django.utils.functional import SimpleLazyObject
|
||||||
|
import graphene
|
||||||
from graphene import Field
|
from graphene import Field
|
||||||
from graphene.relay import Connection, Node
|
from graphene.relay import Connection, Node
|
||||||
from graphene.types.objecttype import ObjectType, ObjectTypeOptions
|
from graphene.types.objecttype import ObjectType, ObjectTypeOptions
|
||||||
|
@ -144,3 +145,8 @@ class DjangoObjectType(ObjectType):
|
||||||
return queryset.get(pk=id)
|
return queryset.get(pk=id)
|
||||||
except cls._meta.model.DoesNotExist:
|
except cls._meta.model.DoesNotExist:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class ErrorType(ObjectType):
|
||||||
|
field = graphene.String(required=True)
|
||||||
|
messages = graphene.List(graphene.NonNull(graphene.String), required=True)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user