【问题标题】:How to upload file using GraphQL view UI如何使用 GraphQL 视图 UI 上传文件
【发布时间】: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


    【解决方案1】:

    好的,我想出了如何测试这个文件上传突变。我使用带有“多部分表单数据”的邮递员并以表单(包括文件)发送参数。效果很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-13
      • 2013-10-24
      • 2021-01-07
      • 2019-10-13
      • 1970-01-01
      • 2021-09-03
      • 2019-03-14
      • 1970-01-01
      相关资源
      最近更新 更多