离子GraphQL错误错误:未捕获(承诺):TypeError:对象(...)

时间:2018-07-20 14:58:59

标签: ionic-framework graphql

我似乎无法从离子应用程序中的graphql服务器获取记录。 我使用django graphene创建了graphql服务器,我尝试按照apollographql网站上的文档进行操作,但是似乎没有。

here is the console

app.module.ts

constructor(
    apollo: Apollo,
    httpLink: HttpLink
  ) {
  apollo.create({
  link: httpLink.create({ uri: "http://127.0.0.1:8000/graphql"}),
  cache: new InMemoryCache()
 });
}

item-service.ts

export class ItemService {
private items: any;

constructor(private apollo: Apollo) {

}

getAll(): Observable<any> {
   const queryWatcher = this.apollo.watchQuery<any>({
     query: queryAllItems
});
return queryWatcher.valueChanges
  .map(result => result.data.allProducts);
}

home.ts

export class HomePage {
    constructor(public nav: NavController, public categoryService: 
        CategoryService, public itemService: ItemService) {
        this.categories = categoryService.getAll();

        this.items$ = itemService.getAll();
     }
}

home.html

<ion-grid class="list-cards">
  <ion-row>
    <ion-col *ngFor="let item of items$ | async" col-6 class="product" 
      (click)="viewItem(item.id)">
    <div class="card light-bg">
      <img src="{{ item.thumb }}" alt="{{ item.name }}">
      <div class="price" text-center>{{ item.price | currency:'USD':true }} 
     </div>
     </div>
   </ion-col>
 </ion-row>
</ion-grid>

0 个答案:

没有答案