4 回答

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超7個(gè)贊
我通過(guò)在配置中將上傳選項(xiàng)設(shè)置為 false 解決了該問(wèn)題ApolloServer
。
new ApolloServer({ schema, context, uploads: false })
然后使用graphqlUploadExpress()
來(lái)自 的中間件graphql-upload
。
app.use(graphqlUploadExpress({ maxFileSize: 10000, maxFiles: 10 }));
希望這對(duì)遇到與我相同問(wèn)題的人有所幫助??

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超11個(gè)贊
請(qǐng)確保您還使用以下客戶端實(shí)現(xiàn)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貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超13個(gè)贊
這取決于您使用的 ApolloClient。
1-如果使用 import { ApolloClient } from 'apollo-client' 必須使用“ createUploadLink ”而不是“ createHttpLink ”意味著,
import { createUploadLink } from 'apollo-upload-client'
const httpLink = createUploadLink({
uri: httpEndpoint,
})
2-如果使用createApolloClient,則精確這個(gè)包:
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貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊
此外,請(qǐng)嘗試確保csrfPrevention您的 ApolloServer 配置中未將其設(shè)置為 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 })],
});
添加回答
舉報(bào)