Lib for adding file upload functionality to GraphQL mutations in Graphene Django and Flask-Graphql
graphene-file-upload is a drop in replacement for the the GraphQL view in Graphene for Django, and for Flask-Graphql. It supports multi-part file uploads that adhere to the Multipart Request Spec.
pip install graphene-file-upload
To add an upload type to your mutation, import and use Upload. Upload is a scalar type.
from graphene_file_upload.scalars import Upload class UploadMutation(graphene.Mutation): class Arguments: file = Upload(required=True) success = graphene.Boolean() def mutate(self, info, file, **kwargs): # do something with your file return UploadMutation(success=True)
To use, import the view, then add to your list of urls (replace previous GraphQL view).
from graphene_file_upload.django import FileUploadGraphQLView urlpatterns = [ url(r'^graphql', FileUploadGraphQLView.as_view(graphiql=True)), ]
Note that flask-graphql version <2.0 is not supported. At the time of writing this README, you must install flask-graphql with pip install --pre flask-graphql
Simply import the modified view and create a new url rule on your app:
from graphene_file_upload.flask import FileUploadGraphQLView app.add_url_rule( '/graphql', view_func=FileUploadGraphQLView.as_view( ... ) )
TO-DO, still need to write tests for Django and Flask views.
Packaging for PyPi:
Build the distribution.
python3 setup.py sdist bdist_wheel
Upload to PyPi test servers.
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Upload to PyPi production servers.
twine upload dist/*
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size graphene_file_upload-1.0.0a2-py3-none-any.whl (4.2 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size graphene_file_upload-1.0.0a2.tar.gz (3.4 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for graphene_file_upload-1.0.0a2-py3-none-any.whl
Hashes for graphene_file_upload-1.0.0a2.tar.gz