Nuxt + GraphQL(Apollo)上传文件

问题描述 投票:0回答:2

我目前正在使用

@nuxt/apollo
模块。该模块是否适用于文件上传,或者我需要将 HTTPLink 更改为另一个?

nuxt.js apollo
2个回答
1
投票

在深入检查库和我的堆栈后,我终于找到了问题所在。 我按照最近的文档对前端和后端进行了非常简单的设置(自从我上次使用它们以来,它们已经发生了巨大的变化),并且我发现显然

@nuxt/apollo
支持开箱即用的文件上传(感谢您周纪尧姆

问题出在我的后端,我必须将

apollo-server-express
"^2.21.0"
更新为
"^3.4.0"
(我正在关注文档,但我拥有的版本较旧,并且不支持文件上传)并按照最近的文档我已经不得不使用
graphqlUploadExpress
中间件并首先启动 GraphQL 服务器,如下所示:

const apolloServer = new ApolloServer({
    schema: schema,
    debug: true,
    context: contextHook
})

export const applyGraphQLMiddleware = async ({ server: app }: { server: Application }) => {
    app.use(graphqlUploadExpress()); // adding this middleware
    await apolloServer.start(); // starting the GraphQL Server 
    apolloServer.applyMiddleware({ app }); // only after that I am applying the express server as a middleware
}

现在文件上传似乎可以正常工作了

以防万一,您可以在 docs

中找到架构和解析器的完整设置

0
投票

无论如何你可以帮助我实现前端..

© www.soinside.com 2019 - 2024. All rights reserved.