Skip to content

Commit

Permalink
Fix error of multiple inputs with the same type. When using same seri…
Browse files Browse the repository at this point in the history
…alizer.
  • Loading branch information
Hispar committed Oct 8, 2018
1 parent f76f38e commit aa8f1ff
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion graphene_django/rest_framework/serializer_converter.py
Expand Up @@ -65,7 +65,7 @@ def convert_serializer_to_input_type(serializer_class):
}

return type(
"{}Input".format(serializer.__class__.__name__),
"{}{}Input".format(serializer.__class__.__name__, serializer._creation_counter),
(graphene.InputObjectType,),
items,
)
Expand Down
@@ -0,0 +1,63 @@
import graphene
import pytest
from django.db import models
from graphene import Schema
from rest_framework import serializers

from graphene_django import DjangoObjectType
from graphene_django.rest_framework.mutation import SerializerMutation

pytestmark = pytest.mark.django_db


class MyFakeChildModel(models.Model):
name = models.CharField(max_length=50)
created = models.DateTimeField(auto_now_add=True)


class MyFakeParentModel(models.Model):
name = models.CharField(max_length=50)
created = models.DateTimeField(auto_now_add=True)
child1 = models.OneToOneField(MyFakeChildModel, related_name='parent1', on_delete=models.CASCADE)
child2 = models.OneToOneField(MyFakeChildModel, related_name='parent2', on_delete=models.CASCADE)


class ParentType(DjangoObjectType):
class Meta:
model = MyFakeParentModel
interfaces = (graphene.relay.Node,)


class ChildType(DjangoObjectType):
class Meta:
model = MyFakeChildModel
interfaces = (graphene.relay.Node,)


class MyModelChildSerializer(serializers.ModelSerializer):
class Meta:
model = MyFakeChildModel
fields = "__all__"


class MyModelParentSerializer(serializers.ModelSerializer):
child1 = MyModelChildSerializer()
child2 = MyModelChildSerializer()

class Meta:
model = MyFakeParentModel
fields = "__all__"


class MyParentModelMutation(SerializerMutation):
class Meta:
serializer_class = MyModelParentSerializer


class Mutation(graphene.ObjectType):
createParentWithChild = MyParentModelMutation.Field()


def test_create_schema():
schema = Schema(mutation=Mutation, types=[ParentType, ChildType])
assert schema

0 comments on commit aa8f1ff

Please sign in to comment.