【发布时间】:2019-11-22 14:50:32
【问题描述】:
这里有一个石墨烯上传文件sn-p (http://docs.graphene-python.org/en/latest/relay/mutations/#accepting-files)。但是,我不确定我们如何在 GraphQL 视图上使用这种突变来上传实际文件。
没有可用的帮助解释如何使用 GraphQL 视图 UI 作为基础上传文件。
class UploadFile(graphene.ClientIDMutation):
class Input:
pass
# nothing needed for uploading file
# your return fields
success = graphene.String()
@classmethod
def mutate_and_get_payload(cls, root, info, **input):
# When using it in Django, context will be the request
files = info.context.FILES
# Or, if used in Flask, context will be the flask global request
# files = context.files
# do something with files
return UploadFile(success=True)
我在 GraphQL 视图上试过这个,
mutation {
upload_image(
) {
success
}
}
这会导致
{
"errors": [
{
"message": "Syntax Error GraphQL (4:3) Expected Name, found )\n\n3: \t\n4: ) {\n ^\n5: success\n",
"locations": [
{
"line": 4,
"column": 3
}
]
}
]
}
【问题讨论】:
标签: flask graphene-python