用于向graphql添加文件上载功能的库graphene django和flask graphql中的突变

graphene-file-upload的Python项目详细描述


https://badge.fury.io/py/graphene-file-upload.svg

石墨烯文件上传

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/*

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在Rxjava中更改列表时通知obsever   java如何验证spring MVC web app中是否设置了连接池?   从Textview选择文本时出现安卓错误(java.lang.IndexOutOfBoundsException:setSpan(1…1)在0之前开始)   javakotlin:作为方法参数的接口   java将列强制转换为hibernate条件中的类型   java如何在屏幕上获取输出对象?   java内部调用方法   java Log4j2模式布局+转换模式处的负数   java将EditText转换为浮动安卓 eclipse   对Java继承规则感到困惑   java将外部文件打包到jar中,然后允许代码对这些打包的文件执行操作   java如何通过输入给定字段之一进行用户搜索?   java Android从应用程序调用活动   java如何从相机中获取图像并将其添加到google地图上作为标记?   java自定义Listview在选择Edittext并打开键盘之前不显示   javascript验证JSON字符串服务端   使用java流从列表中获取素数   java无法让我的菜单打开方法   用户界面高效的动态生成Java GUI