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 309 forks source link

cannot get extract-files implementation to work? #1757

Closed RyannGalea closed 2 years ago

RyannGalea commented 2 years ago

Describe the bug

extract-files won't import now that I'm using v3.

Expected behavior

import { extractFiles } from 'extract-files'

const CreateApolloLink = (httpLink: HttpLink) => {

  const typenameLink = new ApolloLink((operation, forward) => forward(ModifyOperationVariables(operation)))

  const http = httpLink.create({
    uri: environment.graphql,
    method: 'POST',
    useMultipart: true,
    withCredentials: true,
    extractFiles
  })

  return ApolloLink.from([typenameLink, http])
}
Error: Module not found: Error: Package path . is not exported from package C:\outbuild\clientv1\node_modules\extract-files (see exports field in C:\outbuild\clientv1\node_modules\extract-files\package.json)

Is anyone else getting this issue trying to import extractFiles? I'm guessing this has been working for people.

RyannGalea commented 2 years ago

Ok, only works for me when using

Works:

    "extract-files": "11.0.0",

Not working:

    "extract-files": "12.0.0",
digeomel commented 2 years ago

Please update your documentation to the correct way to integrate extract-files in apollo-angular. Even when I use import { extractFiles } from 'extract-files/extractFiles.mjs'; I get a warning in vscode:

Could not find a declaration file for module 'extract-files/extractFiles.mjs'.
'/c/code/myproject/node_modules/extractFiles.mjs' implicitly has an 'any' type.
  Try `npm i --save-dev @types/extract-files` if it exists or add a new declaration (.d.ts) file containing `declare module 'extract-files/extractFiles.mjs';`

And I already did npm i --save-dev @types/extract-files.

RyannGalea commented 2 years ago

I had to revert back to v11 because of this issue also.

digeomel commented 2 years ago

@RyannGalea indeed, the dependency is clearly on v11. However, I can't understand why, because v12 was already out on January 14th, more than a month ago.

In fact, it seems that my mistake was to do npm i --save-dev @types/extract-files, after updating apollo-angular from the alpha version to final 3.0.0, which probably installed v12 and then I started having more problems.

GabrielGil commented 2 years ago

I do not get it either, but my only solution was to use 11. It seems that files are not detected on extract-files@12.

kamilkisiela commented 2 years ago

There's no dependency on extract-files package, you need to provide a function that matches the type signature of extractFiles function. It's up to you to decide which version of extract-files you're using and how to import it really.

GabrielGil commented 2 years ago

The extract-files function works fine v12. As indicated, simply indicate a compatible function.

// 1. Import extractFiles function, and isExtractableFile, which is needed as a second argument of the function.

// Need to ignore the import, because there are no module types, and the ones from @types/extract-files are for v11 yet.
// @ts-ignore
import extractFiles from 'extract-files/extractFiles.mjs';
// @ts-ignore
import isExtractableFile from 'extract-files/isExtractableFile.mjs';

// 2. Set httpLink with an anonymous function to adapt extract-files
httpLink.create({ uri:'yoururl', extractFiles: (body) => extractFiles(body, isExtractableFile) })