4 回答
TA贡献1794条经验 获得超7个赞
我通过在配置中将上传选项设置为 false 解决了该问题ApolloServer
。
new ApolloServer({ schema, context, uploads: false })
然后使用graphqlUploadExpress()
来自 的中间件graphql-upload
。
app.use(graphqlUploadExpress({ maxFileSize: 10000, maxFiles: 10 }));
希望这对遇到与我相同问题的人有所帮助😊
TA贡献1856条经验 获得超11个赞
请确保您还使用以下客户端实现apollo-upload-client:
import { ApolloClient, InMemoryCache } from "@apollo/client";
import { createUploadLink } from 'apollo-upload-client';
const client = new ApolloClient({
cache: new InMemoryCache(),
link: createUploadLink({
uri: 'http://localhost:4000/graphql'
}),
});
TA贡献1842条经验 获得超12个赞
这取决于您使用的 ApolloClient。
1-如果使用 import { ApolloClient } from 'apollo-client' 必须使用“ createUploadLink ”而不是“ createHttpLink ”意味着,
import { createUploadLink } from 'apollo-upload-client'
const httpLink = createUploadLink({
uri: httpEndpoint,
})
2-如果使用createApolloClient,则精确这个包:
import { createApolloClient, restartWebsockets } from 'vue-cli-plugin-apollo/graphql-client'
const { apolloClient, wsClient } = createApolloClient({
...defaultOptions,
...options,
})
``
You do not need to set anything and Upload work complete.
TA贡献1891条经验 获得超3个赞
此外,请尝试确保csrfPrevention您的 ApolloServer 配置中未将其设置为 true
const server = new ApolloServer({
typeDefs,
resolvers,
csrfPrevention: false, // if this is set to true, uploads will fail
uploads: false,
cache: "bounded",
plugins: [ApolloServerPluginLandingPageLocalDefault({ embed: true })],
});
添加回答
举报