用于向graphql添加文件上载功能的库graphene django和flask graphql中的突变
graphene-file-upload的Python项目详细描述
石墨烯文件上传
graphene-file-upload是graphql的替换 在graphene中查看django和flask graphql。它支持 支持Multipart Request Spec的多部分文件上载。
它目前支持Python2.7和3.4+。
安装:
pip install graphene-file-upload
使用量
若要向变异添加上载类型,请导入并使用Upload。 上载是标量类型。
fromgraphene_file_upload.scalarsimportUploadclassUploadMutation(graphene.Mutation):classArguments:file=Upload(required=True)success=graphene.Boolean()defmutate(self,info,file,**kwargs):# do something with your filereturnUploadMutation(success=True)
django集成:
若要使用,请导入视图,然后将其添加到URL列表中(替换上一个 graphql视图)。
fromgraphene_file_upload.djangoimportFileUploadGraphQLViewurlpatterns=[url(r'^graphql',FileUploadGraphQLView.as_view(graphiql=True)),]
烧瓶集成:
请注意,不支持flask-graphql版本<2.0。在 在编写本自述文件时,必须使用 pip install --preflask-graphql
只需导入修改后的视图并在应用程序上创建新的URL规则即可:
fromgraphene_file_upload.flaskimportFileUploadGraphQLViewapp.add_url_rule('/graphql',view_func=FileUploadGraphQLView.as_view(...))
贡献:
如果您想参与,请在发送PR之前运行测试套件。
为了运行测试环境,创建一个虚拟环境,安装 tox,并运行tox命令:
python3 -m venv venv source venv/bin/activate pip install -r requirements-tox.txt # You may have to deactivate and reactivate to have access to the tox command, # depending on your system. # Run the test suite with the versions of python you have installed tox -e py27,py34 # Alternatively, if you're using something like pyenv and can easily install # Multiple versions of python, then try running the following command tox # If for some reason you need to recreate the tox environment (e.g. a new # dependency has been added since you last ran it, add the -r flag to the # tox command) tox -r {...additional flags...}
如果您想要一个简单的方法 安装多个python版本进行测试。
PYPI的包装:
建立发行版。
python3 setup.py sdist bdist_wheel
上传到pypi测试服务器。
twine upload --repository-urlhttps://test.pypi.org/legacy/ dist/*
上传到pypi生产服务器。
twine upload dist/*