graphene-django icon indicating copy to clipboard operation
graphene-django copied to clipboard

serializer_class is required for the SerializerMutation

Open hellpirat opened this issue 8 years ago • 3 comments

class PriceSerializer(serializers.ModelSerializer):
    class Meta:
        model = Price
        fields = '__all__'

class PriceMutation(SerializerMutation):
    class Meta:
        serializer_class = PriceSerializer

django==2.0.8 graphene_django==2.1.0 python 3.7

hellpirat avatar Aug 31 '18 09:08 hellpirat

@hellpirat how did you resolve this issue? I am facing the same issue. When I follow the example https://docs.graphene-python.org/projects/django/en/latest/rest-framework/ here I get this error.

File "/root/Envs/venv/lib/python3.6/site-packages/graphene/utils/subclass_with_meta.py", line 52, in init_subclass super_class.init_subclass_with_meta(**options) File "/root/Envs/venv/lib/python3.6/site-packages/graphene_django/rest_framework/mutation.py", line 60, in init_subclass_with_meta raise Exception("serializer_class is required for the SerializerMutation")

gvbkr avatar Nov 29 '18 23:11 gvbkr

@gvbkr There was a bad import. I did fix it and this is work.

import graphene
import path.to.schema
import path.to.mutations

class Query(
    path.to.schema.Query,
    graphene.ObjectType
):
    pass

class Mutation(graphene.ObjectType):
    mutation_field = path.to.mutations.MutationClass.Field()

schema = graphene.Schema(query=Query, mutation=Mutation)

hellpirat avatar Nov 30 '18 06:11 hellpirat

+1 facing this issue...

exisz avatar Mar 12 '19 09:03 exisz