我正试图用postmen将一个文件上传到graphql服务器。但我得到了这个错误(变量$file得到了无效的值{};上传值无效(。请帮我解决这个问题。我正在使用typegraphql来构建API。
operation: {"query":"mutation($file: Upload!) {n uploadFile(file: $file)n}"}
map: {"0": ["variables.file"]}
0: file.png
如果使用graphql-upload
和apollo-server-express
,则可能需要在ApolloServer
配置中将uploads设置为false,然后从graphql-upload
使用graphqlUploadExpress()
。
例如:
app = express();
new ApolloServer({ schema, context, uploads: false });
app.use(graphqlUploadExpress({ maxFileSize: 10000, maxFiles: 10 }));
server.applyMiddleware({ app });