根据https://apollo-angular.com/docs/data/network#file-upload,为了使用 Apollo Angular 上传文件,您必须添加context: {useMultipart: true}
到 graphQL 查询中,并将该extractFiles
函数添加到 httpLink 创建中。
但是,我不断收到此错误。似乎isExtractableFile
没有使用默认功能,我不知道为什么会这样。
这是我的graphql.module.ts
:
const uri = environment.graphQLUrl; // <-- add the URL of the GraphQL server here
export function createApollo(httpLink: HttpLink): ApolloClientOptions<any> {
return {
link: httpLink.create({uri, useMultipart: true, extractFiles}),
cache: new InMemoryCache(),
};
}
@NgModule({
exports: [ApolloModule],
providers: [
{
provide: APOLLO_OPTIONS,
useFactory: createApollo,
deps: [HttpLink],
},
],
})
export class GraphQLModule {}
Run Code Online (Sandbox Code Playgroud)