```ts // YourPage.component.ts import { Component, OnInit } from '@angular/core'; import { Apollo } from 'apollo-angular'; import gql from 'graphql-tag'; @Component({ selector: 'document-screen', template: `
Loading...
There was an error fetching the data!
`, }) export class SampleGraphqlComponent implements OnInit { user: any = { id: 0, name: 'Some User' }; document: any = { id: 0, title: 'Some Title' }; subdocuments: any = []; error = ''; loading = true; constructor(private apollo: Apollo) {} ngOnInit() { this.apollo .watchQuery({ query: gql` query AllInfoQuery { user { userID name } document { id userID title brief status } subdocuments { id userID title content status } } `, }) .valueChanges.subscribe((result: any) => { this.user = result?.data?.user; this.document = result?.data?.document; this.subdocuments = result?.data?.subdocuments; this.loading = result.loading; // Errors is an array and we're getting the first item only this.error = result.errors[0].message; }); } } ```