apollo Observable asny code example
Example: hwo to get query result in appolo angular
const CurrentUserForProfile = gql`
query CurrentUserForProfile($avatarSize: Int!) {
currentUser {
login
avatar_url(avatarSize: $avatarSize)
}
}
`;
@Component({
template: `
Login: {{currentUser?.profile}}
`,
})
class ProfileComponent implements OnInit, OnDestroy {
currentUser: any;
private querySubscription: Subscription;
ngOnInit() {
this.querySubscription = this.apollo
.watchQuery({
query: CurrentUserForProfile,
variables: {
avatarSize: 100,
},
})
.valueChanges.subscribe(({data}) => {
this.currentUser = data.currentUser;
});
}
ngOnDestroy() {
this.querySubscription.unsubscribe();
}
}