Skip to content

Using interfaces in SerializerMutation #1163

Answered by zbyte64
tuanden0 asked this question in Q&A
Discussion options

You must be logged in to vote

When you say interface do you mean the graphene interfaces like how relay.Node gets used?

In any event, I have used both mixin and decorator patterns to recycle code on mutations.

Sample of a decorator that can wrap the resolver method though I would recommend using a mixin if you can:

def mutate_record_history(Mutation):
    resolver = Mutation._meta.resolver
    # go around frozen
    Mutation._meta.__dict__["resolver"] = wrap_mutation_fn(Mutation, resolver)
    return Mutation

Edit: stackoverflow on mixins: https://stackoverflow.com/questions/533631/what-is-a-mixin-and-why-are-they-useful

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by zbyte64
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1067 on April 14, 2021 20:01.