1

试图进行文件上传的突变。这是我在没有 GraphQL 的情况下尝试过的,它运行良好:

@app.route('/upload', methods=['POST'])
def uploadFile():
    for key in request.files:
        file = request.files[key]
        file.save(os.path.join(UPLOAD_FOLDER, file.filename))

    return 'uploaded'

虽然不确定如何在 GraphQL 中执行此操作,但我想将其包含在我的示例 repo中,以便每个人都知道如何执行此操作。这是我在 Node.js 中用于文件上传的内容

4

1 回答 1

-1

说,您正在上传照片。

class Upload(graphene.Scalar):
    def serialize(self):
        pass

class UploadPhoto(graphene.Mutation):
    class Input:
        photo = Upload()
        id = graphene.String(required=True)

    ok = graphene.Boolean()

    @staticmethod
    def mutate(root, args, context, info):
        files = request.files
        photo = files['variables.photo']

        return UploadPhoto(ok=True)

class MyMutations(graphene.ObjectType):
    upload_photo = UploadPhoto.Field()

schema = graphene.Schema(query=XXX, mutation=MyMutations, types=[Upload])

礼貌:https ://github.com/graphql-python/graphene-django/issues/101#issuecomment-331079482

于 2017-09-26T08:23:19.917 回答