Created
October 29, 2016 10:57
-
-
Save thenationofalex/2ebe8f38ebe7848d75c4c7ee5492a6be to your computer and use it in GitHub Desktop.
GraphQL/Graphene Django - Uploading files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
''' | |
Since Django's request isn't avaliable to graphene's mutation def. | |
It is passed in via context. | |
''' | |
import graphene | |
from .models import Users | |
class UploadMutation(graphene.Mutation): | |
class Input: | |
id = graphene.String() | |
profileImage = graphene.String() | |
def mutate(self, input, context, info): | |
id = input.get('id') | |
user = Users.objects.get(pk=id) | |
if context.FILES and context.method == 'POST': | |
user.image = context.FILES['profileImage'] | |
user.save() | |
return UploadMutation(user=user) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment