Angular NativeScript apollo-angular has no export member ApolloModule

Viewed 2909

I'm very new to GraphQL and tried to use it with NativeScript Angular Project but as I install apollo-angular plugins it does not have any export member of ApolloModule, how can I connect the GRAPHQL server with angulrNativeScrt Project.

import {ApolloModule,  APOLLO_OPTIONS} from 'apollo-angular';
3 Answers

apparently they removed the ApolloModule in version 2.x.

Replace

import {NgModule} from '@angular/core';
import {HttpClientModule} from '@angular/common/http';
import {ApolloModule, APOLLO_OPTIONS} from 'apollo-angular';
import {HttpLinkModule, HttpLink} from 'apollo-angular-link-http';
import {InMemoryCache} from 'apollo-cache-inmemory';

@NgModule({
  imports: [
    // ... other modules
    HttpClientModule,
    HttpLinkModule,
    ApolloModule,
  ],
  providers: [
    {
      provide: APOLLO_OPTIONS,
      useFactory(httpLink: HttpLink) {
        return {
          cache: new InMemoryCache(),
          link: httpLink.create({
            uri: 'http://localhost:3000',
          }),
        };
      },
      deps: [HttpLink],
    },
  ],
})
class AppModule {}

with

import {NgModule} from '@angular/core';
import {HttpClientModule} from '@angular/common/http';
import {APOLLO_OPTIONS} from 'apollo-angular';
import {HttpLink} from 'apollo-angular/http';
import {InMemoryCache} from '@apollo/client/core';

@NgModule({
  imports: [
    // ... other modules
    HttpClientModule,
  ],
  providers: [
    {
      provide: APOLLO_OPTIONS,
      useFactory(httpLink: HttpLink) {
        return {
          cache: new InMemoryCache(),
          link: httpLink.create({
            uri: 'http://localhost:3000',
          }),
        };
      },
      deps: [HttpLink],
    },
  ],
})
class AppModule {}

You can read all abouit it here: https://apollo-angular.com/docs/migration/#no-ngmodules

Are you using apollo-angular version 2.0.x? Try change to version 1.9.1, it's a bug in the new version of apollo-angular (released 6 days ago) or documentation is outdated in apollo angular setup, change to 1.9.1 can solve your problem.

I got the same issue as you, using apollo-angular version 2.0.x, I think the documentation is outdated, I did the following and it fixed the issue

ng add apollo-angular

this will generate automatically graphql.module.ts file which contains

import {NgModule} from '@angular/core';
import {APOLLO_OPTIONS} from 'apollo-angular';
import {ApolloClientOptions, InMemoryCache} from '@apollo/client/core';
import {HttpLink} from 'apollo-angular/http';

const uri = 'your uri'; // <-- add the URL of the GraphQL server here
export function createApollo(httpLink: HttpLink): ApolloClientOptions<any> {
  return {
    link: httpLink.create({uri}),
    cache: new InMemoryCache(),
  };
}

@NgModule({
  providers: [
    {
      provide: APOLLO_OPTIONS,
      useFactory: createApollo,
      deps: [HttpLink],
    },
  ],
})

export class GraphQLModule {}
Related