-
Notifications
You must be signed in to change notification settings - Fork 766
-
I want to using interface with Mutation because there are some fields that I have calculate before return to user.
I can using interface to avoid rewrite code when return a list ojbects or a single object in Query.
But I can't use interface in Mutation to represent data before return to user after create of update it.
So i have to rewrite resolves to create and update.
How can I use interface with Mutation?
Beta Was this translation helpful? Give feedback.
All reactions
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
-
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
Beta Was this translation helpful? Give feedback.
All reactions
-
Great! I solved my problem, thank you for answer.
Beta Was this translation helpful? Give feedback.