[英]Angular NativeScript apollo-angular has no export member ApolloModule
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. 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';
apparently they removed the ApolloModule in version 2.x.显然他们在 2.x 版本中删除了 ApolloModule。
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你可以在这里阅读所有关于它的信息: https://apollo-angular.com/docs/migration/#no-ngmodules
Are you using apollo-angular version 2.0.x?您使用的是apollo-angular版本 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.
尝试更改为1.9.1版本,这是新版本apollo-angular (6 天前发布)中的错误或apollo angular setup中的文档已过时,更改为 1.9.1 可以解决您的问题。
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我遇到了和你一样的问题,使用 apollo-angular 版本 2.0.x,我认为文档已经过时,我做了以下操作并解决了问题
ng add apollo-angular
this will generate automatically graphql.module.ts file which contains这将自动生成 graphql.module.ts 文件,其中包含
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 {}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.