Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error of multiple inputs with the same type. When using same seri…
…alizer.
- Loading branch information
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
graphene_django/rest_framework/tests/test_multiple_model_serializers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |