kamilkisiela / apollo-angular

A fully-featured, production ready caching GraphQL client for Angular and every GraphQL server 🎁
https://apollo-angular.com
MIT License
1.5k stars 311 forks source link

File upload extractFiles issue #2291

Closed gfort-amarena closed 2 months ago

gfort-amarena commented 2 months ago

Hello,

I have an issue regarding the file upload feature of the apollo angular client.

I am setting up the ApolloClient with the link as followed:

link: httpLink.create({
      uri: uri,
      useMultipart: true,
      extractFiles: (body) => extractFiles(body, isExtractableFile),
    }),

But I always get this compile error:

 [ERROR] TS2322: Type '(body: Body | Body[]) => Extraction<ExtractableFile>' is not assignable to type 'ExtractFiles'.
  Call signature return types 'Extraction<ExtractableFile>' and '{ clone: Body; files: Map<any, any>; }' are incompatible.
    The types of 'clone' are incompatible between these types.
      Type 'unknown' is not assignable to type 'Body'. [plugin angular-compiler]

    graphql.provider.ts:16:6:
      16 │       extractFiles: (body) => extractFiles(body, isExtractableFile),
         ╵       ~~~~~~~~~~~~

  The expected type comes from property 'extractFiles' which is declared here on type 'Options'

    node_modules/apollo-angular/http/types.d.ts:20:4:
      20 │     extractFiles?: ExtractFiles;
         ╵     ~~~~~~~~~~~~

The documentation and github issues only refer to this way of setting up the file upload feature but I can't find a way to make it work.

It looks like a bug to me but I am really not sure.

Thanks for your help,

Environment:

├── @angular/cli@18.2.1
├── @angular/core@18.2.1
├── @apollo/client@3.11.4
├── apollo-angular@7.1.2
├── graphql@16.9.0
└── typescript@5.5.4
gfort-amarena commented 2 months ago

The solution is so simple...

extractFiles(body) {
  return extractFiles(body, isExtractableFile) as any;
}

Would be nice to upload the documentation though.

PowerKiKi commented 1 month ago

Thanks for reporting. This will be fixed in the upcoming version, that will include #2292.