首页 > 解决方案 > graphql apollo-server 中的文件上传错误

问题描述

我正在学习graphql。我关注了这篇文章https://dev.to/dnature/handling-file-uploads-with-apollo-server-2-0-14n7#:~:text=With%20Apollo%20Server%202.0% 2C%20you,a%20cloud%20storage%20provider%20 代替。用于使用 graphql apollo-server 上传文件,但在图像文件夹中为响应和空文件获得无限缓冲。

我确定错误是在以下两个文件中

突变文件

架构文件

标签: node.jsfileuploadgraphqlapollo-server

解决方案


您需要graphql-upload使用yarn add graphql-upload. 然后你需要在 ApolloServer 创建到主服务器文件中做一些更改,

const apolloServer = new ApolloServer({
    schema,
    resolvers,
    uploads: false, // add this
  });

然后你需要从你的主服务器文件中添加graphqlUploadExpress中间件,graphql-upload

  app.use(graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }));

有关更多信息,请参阅此 github 问题https://github.com/MichalLytek/type-graphql/issues/37#issuecomment-592467594


推荐阅读