Skip to content

Commit 923d828

Browse files
patrick91jkimbo
authored andcommitted
Fix duplicated ErrorType declaration (#539)
* Add failing test case * Fix duplicated ErrorType declaration
1 parent 0a5020b commit 923d828

File tree

6 files changed

+52
-7
lines changed

6 files changed

+52
-7
lines changed

graphene_django/forms/mutation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from graphene_django.registry import get_global_registry
1515

1616
from .converter import convert_form_field
17-
from .types import ErrorType
17+
from ..types import ErrorType
1818

1919

2020
def fields_for_form(form, only_fields, exclude_fields):

graphene_django/rest_framework/mutation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from graphene.types.objecttype import yank_fields_from_attrs
1010

1111
from .serializer_converter import convert_serializer_field
12-
from .types import ErrorType
12+
from ..types import ErrorType
1313

1414

1515
class SerializerMutationOptions(MutationOptions):

graphene_django/rest_framework/types.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
from graphene.types.unmountedtype import UnmountedType
33

44

5-
class ErrorType(graphene.ObjectType):
6-
field = graphene.String(required=True)
7-
messages = graphene.List(graphene.NonNull(graphene.String), required=True)
8-
9-
105
class DictType(UnmountedType):
116
key = graphene.String()
127
value = graphene.String()

graphene_django/tests/issues/__init__.py

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# https://github.com/graphql-python/graphene-django/issues/520
2+
3+
import datetime
4+
5+
from django import forms
6+
7+
import graphene
8+
9+
from graphene import Field, ResolveInfo
10+
from graphene.types.inputobjecttype import InputObjectType
11+
from py.test import raises
12+
from py.test import mark
13+
from rest_framework import serializers
14+
15+
from ...types import DjangoObjectType
16+
from ...rest_framework.models import MyFakeModel
17+
from ...rest_framework.mutation import SerializerMutation
18+
from ...forms.mutation import DjangoFormMutation
19+
20+
21+
class MyModelSerializer(serializers.ModelSerializer):
22+
class Meta:
23+
model = MyFakeModel
24+
fields = "__all__"
25+
26+
27+
class MyForm(forms.Form):
28+
text = forms.CharField()
29+
30+
31+
def test_can_use_form_and_serializer_mutations():
32+
class MyMutation(SerializerMutation):
33+
class Meta:
34+
serializer_class = MyModelSerializer
35+
36+
class MyFormMutation(DjangoFormMutation):
37+
class Meta:
38+
form_class = MyForm
39+
40+
class Mutation(graphene.ObjectType):
41+
my_mutation = MyMutation.Field()
42+
my_form_mutation = MyFormMutation.Field()
43+
44+
graphene.Schema(mutation=Mutation)

graphene_django/types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from django.db.models import Model
55
from django.utils.functional import SimpleLazyObject
6+
import graphene
67
from graphene import Field
78
from graphene.relay import Connection, Node
89
from graphene.types.objecttype import ObjectType, ObjectTypeOptions
@@ -144,3 +145,8 @@ def get_node(cls, info, id):
144145
return queryset.get(pk=id)
145146
except cls._meta.model.DoesNotExist:
146147
return None
148+
149+
150+
class ErrorType(ObjectType):
151+
field = graphene.String(required=True)
152+
messages = graphene.List(graphene.NonNull(graphene.String), required=True)

0 commit comments

Comments
 (0)