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

Created on 27 Oct 2019  路  15Comments  路  Source: kamilkisiela/apollo-angular

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?

Most helpful comment

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.

All 15 comments

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

Likewise

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

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 [email protected], so that we can talk. Thank you.

It鈥檚 taking time. We need to fix that

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

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.

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.

@joacorandom You could create a repository with basic reproduction

@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.

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

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

@kamilkisiela could you please reopen this one?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

juliescript picture juliescript  路  7Comments

patriknil90 picture patriknil90  路  7Comments

miquelferrerllompart picture miquelferrerllompart  路  7Comments

bkinsey808 picture bkinsey808  路  3Comments

kobojsaren picture kobojsaren  路  6Comments