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

Apollo has a constructor which is not compatible with Dependency Injection. It should probably not be @Injectable(). #1376

Closed
Napas opened this issue Oct 27, 2019 · 19 comments

Comments

@Napas
Copy link

Napas commented Oct 27, 2019

I was following documentation from the https://www.apollographql.com/docs/angular/basics/setup/ trying to install Apollo Angular.

After running ng add apollo-angular and updating API endpoint in the graphql.module.ts, I'm getting Apollo has a constructor which is not compatible with Dependency Injection. It should probably not be @Injectable(). when trying to inject Apollo from apollo-angular in any component or service.

Angular version: 8.2.11
Angular Apollo version: 1.8.0

How this could be resolved?

@wSedlacek
Copy link

wSedlacek commented Nov 3, 2019

This issue only shows up for me when "angularCompilerOptions": { "enableIvy": true },
Hope it can be resolved soon!

@TamirShklaz
Copy link

Likewise

@jogelin
Copy link

jogelin commented Nov 7, 2019

Same issue for me...

This error look like something that could be related to (https://next.angular.io/guide/ivy-compatibility)

All classes that use Angular DI must have an Angular decorator like @directive() or @Injectable (previously, undecorated classes were allowed if an ancestor class or subclass had a decorator).

May this library could help to validate apollo ?!: https://github.com/angular/ngcc-validation

@CharlieGreenman
Copy link

CharlieGreenman commented Nov 13, 2019

Anyone working on this?
Update:
Going to post my findings as tracking down bug:
File in question: src/Apollo.ts

  1. Currently dissecting the constructor: (Line 112-120)
constructor(
    private _ngZone: NgZone,
    @Optional()
    @Inject(APOLLO_OPTIONS)
    apolloOptions?: ApolloClientOptions<any>,
    @Optional()
    @Inject(APOLLO_NAMED_OPTIONS)
    apolloNamedOptions?: NamedOptions,
  ) {

Looking to see what changed with constructor to make it so that it thinks this shouldn't be an injectable

  1. Also looking through recent history on @angular/core/core.d.ts file to see if anything recently changed in declaration file. Will tell if has to do with recent change here, or in @angular/core

At this point stuck:
Trying to figure out why __ivy_ngcc__ is automatically being added to package, and new builds that I am making aren't being picked up? At this time rolling back packages, so can continue working on app. I do not know core contributors personally, but would love if can reach out to charlie@razroo.com, so that we can talk. Thank you.

@sidymbengue25
Copy link

It’s taking time. We need to fix that

@Vilsol
Copy link

Vilsol commented Nov 20, 2019

This problem goes away if you switch to Angular 9 RC releases, e.g. 9.0.0-rc.2

@kamilkisiela
Copy link
Owner

There's no stable Angular 9 yet so you guys please give me time to solve it. I started creating apollo-angular when Angular was in alpha, then in beta and then they changed bunch of stuff in one of RCs.

As @Vilsol pointed out. It's no longer an issue in 9.0.0-rc.2.

It's an open-source project and I'm the only one developing it (Apollo Team haven't pushed a single line of code). If you want to help, please provide reproductions or even pull requests, this speeds up things a lot.

@joacorandom
Copy link

There is some way to help you with this fix? Can you give me some pointers around this?
I need to fix this soon and I'm willing to help to get this quickier.

@kamilkisiela
Copy link
Owner

@joacorandom You could create a repository with basic reproduction

@joacorandom
Copy link

@wSedlacek
Copy link

@kamilkisiela I want to personally thank you for all your work. This project is awesome. I really do appreciate you taking the time to look into this. Thank you.

@Nielsb85
Copy link

I am only having this issue when running unit tests. is there any solution for this already?

@PowerKiKi
Copy link
Collaborator

According to #1466 (comment), #1466 (comment) and #1376 (comment). It seems it's been resolved and this issue should be closed.

@Maximaximum
Copy link

Seems like the issue hasn't been fixed yet. I'm still facing it with Angular 12

@Maximaximum
Copy link

@kamilkisiela could you please reopen this one?

@WolfSoko
Copy link

WolfSoko commented Sep 9, 2021

Maybe it is due to a missing @Injectable decorator at the BaseApollo class.

@Maximaximum
Copy link

@WolfSoko No, as I've found out, this issue is caused by a bug in jest-preset-angular, which is not able to properly handle es6 namespace imports. And such imports are (in my case) generated by graphql code generator. This is the issue: thymikee/jest-preset-angular#963

@Nielsb85 @CharlieGreenman @Napas could you please confirm if you were experiencing this issue when using jest with angular?

@Nielsb85
Copy link

Nielsb85 commented Sep 9, 2021 via email

@WolfSoko
Copy link

@Maximaximum Good to know. I can confirm that I have the DI Problems when using jest and the generated queries from graphql code generator.

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