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.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4dfb4ec9132fc613143b14e3b15d8a306b7373b6a23c343bb83279af2cf7ba1 |
|
MD5 | b22a605d357e2722c443bc5f83aa2f11 |
|
BLAKE2b-256 | 4e2ff6aecd4a3e02bc73653ee3c3145a6442b96e657d3ccce11ced6100d56fda |
Hashes for graphene_file_upload-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c3688859b8e5aa79979a286e3de55284fd0cc43c527352bcca6de17e8fd9828b |
|
MD5 | 4b80ed3a75e7a096b19da1257d093754 |
|
BLAKE2b-256 | 9e338592453fa9ea3a360932aa16116b7910f03c4e66b53dde5a1201b5921cee |