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

Please add Ahead of time compile support #119

Closed
chriswep opened this issue Oct 8, 2016 · 10 comments
Closed

Please add Ahead of time compile support #119

chriswep opened this issue Oct 8, 2016 · 10 comments
Assignees
Milestone

Comments

@chriswep
Copy link

chriswep commented Oct 8, 2016

e.g. needed for Ionic 2 RC0

@stubailo
Copy link
Contributor

stubailo commented Oct 8, 2016

Can you go into detail about what is blocking it from working?

@kamilkisiela
Copy link
Owner

@metzc I'm going to work on it but not in next few days. If anyone wants to create a PR, it would be nice :)

@stubailo An extended tsc but supports html etc. This way all templates are being compiled to js and external html and css is bundled within an app.

This way you get templates compiled to JS:

// many of
document.createElement(/* ... */)

instead of:

<input *ngIf="!something" [(ngModel)]="bar" />

@stubailo
Copy link
Contributor

Sure, I guess I'm wondering why this repository has to be involved in that. Isn't compiling the code some other tool's problem?

@kamilkisiela
Copy link
Owner

It has few requirements and if I remember correctly angular2-apollo doesn't fulfills them (or at least one). I haven't looked deeper into this, did a quick attempt to see if it works, that's all.

@chriswep
Copy link
Author

chriswep commented Oct 11, 2016

as @stubailo said there are requirements. This post has some useful hints: https://medium.com/@isaacplmann/making-your-angular-2-library-statically-analyzable-for-aot-e1c6f3ebedd5#.pbg52i3qt

Part of the problem is also the apollo-client library where i created a seperate issue: apollographql/apollo-client#758

I tried to do some fixes myself and i found out that the ApolloModule.withClient(client) method does not work that way with AOT. I could make it to work by changing the module code to the way it was done by ng2-translate: https://github.com/ocombe/ng2-translate/blob/master/ng2-translate.ts (this stackoverflow post also seems to confirm the solution: https://stackoverflow.com/questions/39948342/making-aot-compatible-di)

This would break the tutorial and i think also requires changes i have done to the apollo-client library (removing the default export), so a pull request now wouldn't make sense i assume.

@kamilkisiela kamilkisiela self-assigned this Oct 14, 2016
@kamilkisiela kamilkisiela added this to the v0.6.0 milestone Oct 14, 2016
@kamilkisiela kamilkisiela modified the milestones: v0.6.0, v0.7.0 Oct 26, 2016
@vangorra
Copy link

Instead of using ApolloModule.withClient(APOLLO_CLIENT), I ended up using a provider factory. Here is my work around.

constants/ApolloClient.ts

....
export const APOLLO_CLIENT = new ApolloClient({
    networkInterface: NETWORK_INTERFACE
});

export function apolloClientFactory(): ApolloClient {
    return APOLLO_CLIENT;
}

modules/AppModule.ts

@NgModule({
...
providers: [
   ...
   {
        provide: Angular2Apollo,
        useFactory: apolloClientFactory
    }
]

@kamilkisiela
Copy link
Owner

DONE! 🚀 #124

@kamilkisiela
Copy link
Owner

And an example

@geocine
Copy link

geocine commented Nov 12, 2016

for some reason I could still not make your example work on ionic 2. I am using the correct versions of packages?

"angular2-apollo": "^0.8.0",
"apollo-client": "^0.5.2",

@geocine
Copy link

geocine commented Nov 12, 2016

Sorry I have now solved it , I did not notice it should be

export {
    client
}

not

export const client = ...

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

5 participants