Lib for adding file upload functionality to GraphQL mutations in Graphene Django and Flask-Graphql
Project description
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.
Installation:
pip install graphene-file-upload
Usage
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)
Django Integration:
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)),
]
Flask Integration:
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(
...
)
)
Testing:
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/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for graphene_file_upload-1.0.0a2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 779bfc8aba1f66af0274e1ce28ead3b47d336e5fef94734eb2055ea4cc93ed85 |
|
MD5 | a474f88a2de7015f41115c00ba2a6d83 |
|
BLAKE2b-256 | e93bdbe70d8f57a822ba63c47d82e76fed13c9e08d448647b4e1bb34b26dc4d0 |
Hashes for graphene_file_upload-1.0.0a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3144e66137d66ead4f67e093c63349ca5f5d216e92d8891bdd755a8c0987e504 |
|
MD5 | cc087593a1d8acac2f3bcc82f1584c1c |
|
BLAKE2b-256 | 7454fb85c9e2b88cf372b2e642b11a5cce128d96547126895a302d29181adb74 |