Skip to content
This repository has been archived by the owner on Nov 23, 2020. It is now read-only.

default ng build --prod generating console errors #273

Open
agborkowski opened this issue Dec 11, 2018 · 2 comments
Open

default ng build --prod generating console errors #273

agborkowski opened this issue Dec 11, 2018 · 2 comments
Labels
angular Related to @loona/angular bug Something isn't working

Comments

@agborkowski
Copy link

ng build --prod generates

main.568598cebae93c2a7f2b.js:1 Uncaught Error: 
        In order to initialize Apollo Client, you must specify link & cache properties on the config object.
        This is part of the required upgrade when migrating from Apollo Client 1.0 to Apollo Client 2.0.
        For more information, please visit:
          https://www.apollographql.com/docs/react/basics/setup.html
        to help you get started.
@kamilkisiela kamilkisiela added bug Something isn't working angular Related to @loona/angular labels Dec 21, 2018
@ceelian
Copy link

ceelian commented Mar 16, 2019

Got the same error in production. Any workaround we can get loona run in angular prod mode?

@ceelian
Copy link

ceelian commented Mar 16, 2019

Found the source of the problem and a solution:

const uri = '/graphql/';

export function apolloFactory(
  httpLink: HttpLink,
  loonaLink: LoonaLink,
  cache: InMemoryCache
): ApolloClientOptions<any> {
  const link = loonaLink.concat(
    httpLink.create({
      uri: uri
    })
  );

  return {
    link,
    cache
  };
}

@NgModule({
  imports: [
    ApolloModule,
    LoonaModule.forRoot([FooState, BarState])
  ],
  exports: [ApolloModule, HttpLinkModule],
  providers: [
    {
      provide: LOONA_CACHE,
      useValue: new InMemoryCache() // <-- works in prod mode (with aot)
      // useFactory() {  <-- does NOT work with aot (in prod mode)
      //   return new InMemoryCache();
      // }
    },
    {
      provide: APOLLO_OPTIONS,
      useFactory: apolloFactory,
      deps: [HttpLink, LoonaLink, LOONA_CACHE]
    }
  ]
})
export class GraphqlModule {
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
angular Related to @loona/angular bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants