【问题标题】:File upload error in graphql apollo-servergraphql apollo-server 中的文件上传错误
【发布时间】:2021-03-02 22:39:48
【问题描述】:

我正在学习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%20instead。用于使用 graphql apollo-server 上传文件,但在图像文件夹中为响应和空文件获得无限缓冲。

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

mutation file

schema file

【问题讨论】:

    标签: node.js file upload graphql apollo-server


    【解决方案1】:

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

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

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

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

    更多信息请参考这个github问题https://github.com/MichalLytek/type-graphql/issues/37#issuecomment-592467594

    【讨论】:

      猜你喜欢
      • 2021-12-10
      • 2019-04-30
      • 2019-12-30
      • 2019-04-04
      • 1970-01-01
      • 2021-10-13
      • 2020-04-03
      • 2017-05-24
      • 2018-10-21
      相关资源
      最近更新 更多