【问题标题】:"ERROR Error: Argument 2 `isExtractable` must be a function." when uploading files with Apollo Angular\"ERROR Error: Argument 2 `isExtractable` must be a function.\" 使用 Apollo Angular 上传文件时
【发布时间】:2022-10-05 20:21:17
【问题描述】:

根据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 {}
  • 您是否尝试过使用链接的 Angular 文档中的 extractFiles 函数示例来查看两者之间是否存在任何差异?

标签: angular file-upload graphql apollo apollo-client


【解决方案1】:

编写自己的函数会更好。 在这里查看我的要点:custom extract files function

【讨论】:

    猜你喜欢
    • 2017-04-08
    • 1970-01-01
    • 2018-05-09
    • 2018-01-18
    • 2013-09-22
    • 1970-01-01
    • 2021-02-26
    • 2017-03-09
    • 2017-11-16
    相关资源
    最近更新 更多