Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File upload extractFiles issue #2291

Closed
gfort-amarena opened this issue Sep 10, 2024 · 2 comments
Closed

File upload extractFiles issue #2291

gfort-amarena opened this issue Sep 10, 2024 · 2 comments

Comments

@gfort-amarena
Copy link

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
Copy link
Author

The solution is so simple...

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

Would be nice to upload the documentation though.

@PowerKiKi
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants