-
Notifications
You must be signed in to change notification settings - Fork 767
Closed
Description
Hi,
I'm using the SerializerMutation class to attempt to create mutations based off of my existing Rest Framework serializers. By taking advantage of the ModelSerializer in DRF, I hoped to avoid having to create all the mutations from scratch with validation and whatnot.
However, the use of the SerializerMutation class isn't sufficiently explained in the docs. I did this
class ItemMutation(SerializerMutation):
class Meta:
serializer_class = ItemSerializer
class Mutation(AbstractType):
#...other mutations...
createItem = ItemMutation.Field()
from a simple DRF ModelSerializer
class ItemSerializer(serializers.ModelSerializer):
class Meta:
model = Item
fields = (
'id',
'name',
'description',
'website',
)
But Graphiql shows me the following error whenever I try to use the mutation
mutation newItem($data: ItemMutationInput!) {
createItem(input: $data) {
name,
description
}
}
{
"data": {
"name": "Blah",
"description": "Blah blah blah",
"website": "https://blah.blah.blah"
}
}
{
"errors": [
{
"message": "'NoneType' object is not callable",
"locations": [
{
"line": 2,
"column": 3
}
]
}
],
"data": {
"createItem": null
}
}
Also, Rest Framework's serializers can often have multiple actions (mutations) like create, delete, update, etc and the use of SerializerMutation appears to just produce a single mutation - presumably the "create" action. How do I handle the other actions?
Metadata
Metadata
Assignees
Labels
No labels