How to write update function with graphene-django
See original GitHub issueI am imprementing update function of the attribute of User with graphene-django
Of course we implement it as a mutation, mutate can be written with kwargs, We have to define all elements in Arguments class and field settings after all.
- how can we update only one element, for example?
Currently, I can not update without passing all elements
- How can I write these well with kwargs?
I want to change that there are three rewriting places for changing elements.(setting filed, arg, return)
thank you
class UpdateUser(graphene.Mutation):
user = graphene.Field(UserType)
username = graphene.String(required=True)
first_name = graphene.String(required=True)
last_name = graphene.String(required=True)
#???password = graphene.String(required=True)
email = graphene.String(required=True)
class Arguments:
username = graphene.String(required=True)
first_name = graphene.String(required=True)
last_name = graphene.String(required=True)
#???password = graphene.String(required=True)
email = graphene.String(required=True)
@login_required
def mutate(self, info, **kwargs):
user = info.context.user
for k, v in kwargs.items():
user.k = v
# user.set_password(password)
user.save()
return UpdateUser(username=username,
first_name=first_name,
last_name=last_name,
email=email )
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
Mutations - Graphene-Python
Graphene -Django makes it easy to perform mutations. With Graphene-Django we ... Use the method get_serializer_kwargs to override how updates are applied.
Read more >Create or Update Update a many-many ... - Stack Overflow
This should fix it obj, created = models.Rating.objects.update_or_create( user_id=user, movie_id=movie, defaults={"rating": rating} ).
Read more >Building GraphQL APIs in Django with Graphene - Twilio
Learn how to build a GraphQL API in Django using the Graphene package.
Read more >GraphQL with Django — simple yet powerful (CRUD) — Part 2
So this time around we're going to dive-in deep and cover all the CRUD operations (Create, Read, Update, Delete). But as far as...
Read more >Django + Graphene: From REST to GraphQL - FullStack Labs
Graphene provides us with a schema object attached with resolve methods to fetch data. In Django, we are accustomed to creating apps according...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments