GraphQL - 尝试使用 apolloUploadExpress 上传文件时出错

GraphQL - Error while trying to upload files with apolloUploadExpress

你好吗? 我正在尝试配置我的 graphql 服务器以允许随我的突变一起发送文件。 我已经尝试了几种方法,现在我正在尝试使用 apolloUploadExpress,但直到那时都没有成功。 我的服务器初始化如下所示:

const app = express();
app.use('/graphql', bodyParser.json(), 
apolloUploadExpress({
uploadDir: '/home/xxx/projects/xx/upload/'
 }),
graphqlExpress(req => {
return {
    context: {
        req
    },
    graphiql: true,
    schema,
    rootValue: root
};
}));

我的卷曲看起来像这样:

curl -X POST   http://localhost:5000/graphql     -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'   -H 'postman-token: 7c5230d1-1605-6559-7609-ab373934831e'   -F 'query={"query":"mutation{\n  setImage(input:{clientMutationId:\"123\", id:\"123\", part:\"asda\"}){\n    clientMutationId\n  }\n}","variables":null}'   -F file=@/home/xxxxx/Pictures/cat.jpg

当我执行 curl 时出现错误。在 graphql 控制台中显示:

undefined:1 undefined ^

SyntaxError: Unexpected token u in JSON at position 0 at Object.parse

有人可以帮我解决这个问题吗?

有类似的问题。确保包含

上传:在您的解析器中上传 GraphQL

https://github.com/jaydenseric/apollo-upload-server#upload-scalar