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

Hard to debug compile errors when using the wrong import for the `gql` tag #1601

Closed roschlau closed 3 years ago

roschlau commented 3 years ago

In my Angular project, if I accidentally import { gql } from '@apollo/client' instead of import { gql } from 'apollo-angular', I get the following errors when compiling the project:

ERROR in ./node_modules/@apollo/client/react/context/ApolloConsumer.js
Module not found: Error: Can't resolve 'react' in 'C:\source\echometer\frontend\node_modules\@apollo\client\react\context'

ERROR in ./node_modules/@apollo/client/react/context/ApolloProvider.js
Module not found: Error: Can't resolve 'react' in 'C:\source\echometer\frontend\node_modules\@apollo\client\react\context'

ERROR in ./node_modules/@apollo/client/react/context/ApolloContext.js
Module not found: Error: Can't resolve 'react' in 'C:\source\echometer\frontend\node_modules\@apollo\client\react\context'

ERROR in ./node_modules/@apollo/client/react/hooks/useApolloClient.js
Module not found: Error: Can't resolve 'react' in 'C:\source\echometer\frontend\node_modules\@apollo\client\react\hooks'

ERROR in ./node_modules/@apollo/client/react/hooks/useReactiveVar.js
Module not found: Error: Can't resolve 'react' in 'C:\source\echometer\frontend\node_modules\@apollo\client\react\hooks'

ERROR in ./node_modules/@apollo/client/react/hooks/useSubscription.js
Module not found: Error: Can't resolve 'react' in 'C:\source\echometer\frontend\node_modules\@apollo\client\react\hooks'

ERROR in ./node_modules/@apollo/client/react/hooks/useMutation.js
Module not found: Error: Can't resolve 'react' in 'C:\source\echometer\frontend\node_modules\@apollo\client\react\hooks'

ERROR in ./node_modules/@apollo/client/react/hooks/utils/useBaseQuery.js
Module not found: Error: Can't resolve 'react' in 'C:\source\echometer\frontend\node_modules\@apollo\client\react\hooks\utils'

ERROR in ./node_modules/@apollo/client/react/hooks/utils/useDeepMemo.js
Module not found: Error: Can't resolve 'react' in 'C:\source\echometer\frontend\node_modules\@apollo\client\react\hooks\utils'

It would be nice to at least have some way to pinpoint the error in this case - took me a good while of trial and error until I found the culprit. I've added an import-blacklist entry for the offending import in my tslint.json, but that only becomes an option once you know about the actual problem, and might not be an option for others at all.

Environment:

fetis commented 3 years ago

I experienced the same issue recently, but I have no idea how it can be solved on the library level.

nthornton2010 commented 3 years ago

The only way this library would be able to do anything about it is by renaming it's version of gql to something different so that the compiler doesn't suggest multiple choices. I'd say the real issue is with the @apollo library for not separating their code base into react and angular directories.

It's annoying but something that I think all apollo devs outside of react are forced to live with.

At the end of the day, I don't think this is the responsibility of this library.

fetis commented 3 years ago

There's nothing to do from our side. If someone will come up with an idea of how to prevent this, let's us know. For now, I close it.