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條經驗 獲得超13個贊
這取決于您使用的 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 })],
});
添加回答
舉報