Skip to main content

Lib for adding file upload functionality to GraphQL mutations in Graphene Django

Project description

graphene-file-upload is a drop in replacement for the the GraphQL view in Graphene for Django. It supports multi-part file uploads that adhere to the Multipart Request Spec (https://github.com/jaydenseric/graphql-multipart-request-spec).

Installation:

pip install graphene-file-upload

Usage:

To use, import the view, then add to your list of urls (replace previous GraphQL view).

from graphene_file_upload import ModifiedGraphQLView

urlpatterns = [
  url(r'^graphql', ModifiedGraphQLView.as_view(graphiql=True)),
]

To add an upload type to your mutation, import and use Upload. Upload is a scalar type.

from graphene_file_upload import Upload

class UploadMutation(graphene.Mutation):
    class Arguments:
        file = Upload(required=True)

    success = graphene.Boolean()

    def mutate(self, info, file, **kwargs):
        # file parameter is key to uploaded file in FILES from context
        uploaded_file = info.context.FILES.get(file)
        # do something with your file

        return UploadMutation(success=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for graphene-file-upload, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size graphene_file_upload-0.1.1-py2.py3-none-any.whl (3.3 kB) File type Wheel Python version py2.py3 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page