ANGULAR SSR with graphql and apollo, transferState doesn't transfer to client side

Viewed 23

I have an angular aplications, which shows articles on first page. I don't want that api call is executed twice, first on the server and once on the client side, so I used transfer state to check if api was already called. If I use REST API everything works fine and api call is executed on server only but when I add graphql with apollo this doesen't seems to work.

async ngOnInit() {
let myTransferStateKey = makeStateKey<any>('myDatas');

if (this.transferState.hasKey(myTransferStateKey)) {
  console.log('HomeComponent ngOnInit hasKey');
  this.transferState.get(myTransferStateKey, [])
  this.transferState.remove(myTransferStateKey);
} else {
  console.log('HomeComponent ngOnInit noKey');
  
  this.posts = (await this.graphql.query(this.home_query)) as {
    capital: string
    currency: string
    languages: []
    name: string
    native: string
  }[] 

  this.transferState.set(myTransferStateKey, this.posts) 
  
}

}

0 Answers
Related