```ts filename="YourPage.component.ts" renderer="angular" language="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; }); } } ``` ```js filename="YourPage.jsx" renderer="react" language="js" import { useQuery, gql } from '@apollo/client'; import { PageLayout } from './PageLayout'; import { DocumentHeader } from './DocumentHeader'; import { DocumentList } from './DocumentList'; const AllInfoQuery = gql` query AllInfo { user { userID name } document { id userID title brief status } subdocuments { id userID title content status } } `; function useFetchInfo() { const { loading, error, data } = useQuery(AllInfoQuery); return { loading, error, data }; } export function DocumentScreen() { const { loading, error, data } = useFetchInfo(); if (loading) { return

Loading...

; } if (error) { return

There was an error fetching the data!

; } return ( ); } ``` ```ts filename="YourPage.tsx" renderer="react" language="ts" import { useQuery, gql } from '@apollo/client'; import { PageLayout } from './PageLayout'; import { DocumentHeader } from './DocumentHeader'; import { DocumentList } from './DocumentList'; const AllInfoQuery = gql` query AllInfo { user { userID name } document { id userID title brief status } subdocuments { id userID title content status } } `; interface Data { allInfo: { user: { userID: number; name: string; opening_crawl: boolean; }; document: { id: number; userID: number; title: string; brief: string; status: string; }; subdocuments: { id: number; userID: number; title: string; content: string; status: string; }; }; } function useFetchInfo() { const { loading, error, data } = useQuery(AllInfoQuery); return { loading, error, data }; } export function DocumentScreen() { const { loading, error, data } = useFetchInfo(); if (loading) { return

Loading...

; } if (error) { return

There was an error fetching the data!

; } return ( ); } ``` ```js filename="YourPage.jsx" renderer="solid" language="js" import { Match, Switch } from 'solid-js'; import { createGraphQLClient, gql } from '@solid-primitives/graphql'; import { PageLayout } from './PageLayout'; import { DocumentHeader } from './DocumentHeader'; import { DocumentList } from './DocumentList'; const newQuery = createGraphQLClient('https://foobar.com/v1/api'); const AllInfoQuery = gql` query AllInfo { user { userID name } document { id userID title brief status } subdocuments { id userID title content status } } `; function useFetchInfo() { const [data] = newQuery(AllInfoQuery, { path: 'home' }); return data; } export function DocumentScreen() { const data = useFetchInfo(); return (

Loading...

There was an error fetching the data!

{(data) => ( )}
); } ``` ```ts filename="YourPage.tsx" renderer="solid" language="ts" import { createGraphQLClient, gql } from '@solid-primitives/graphql'; import { PageLayout } from './PageLayout'; import { DocumentHeader } from './DocumentHeader'; import { DocumentList } from './DocumentList'; const newQuery = createGraphQLClient('https://foobar.com/v1/api'); const AllInfoQuery = gql` query AllInfo { user { userID name } document { id userID title brief status } subdocuments { id userID title content status } } `; interface Data { allInfo: { user: { userID: number; name: string; opening_crawl: boolean; }; document: { id: number; userID: number; title: string; brief: string; status: string; }; subdocuments: { id: number; userID: number; title: string; content: string; status: string; }; }; } function useFetchInfo() { const [data] = newQuery(AllInfoQuery, { path: 'home' }); return data; } export function DocumentScreen() { const data = useFetchInfo(); return (

Loading...

There was an error fetching the data!

{(data) => ( )}
); } ``` ```html filename="YourPage.vue" renderer="vue" language="js" ``` ```html filename="YourPage.vue" renderer="vue" language="ts" ``` ```svelte filename="YourPage.svelte" renderer="svelte" language="js" {#if $infoResult.loading}

Loading...

{:else if $infoResult.error}

There was an error fetching the data!

{:else} {/if} ``` ```svelte filename="YourPage.svelte" renderer="svelte" language="ts" {#if $infoResult.loading}

Loading...

{:else if $infoResult.error}

There was an error fetching the data!

{:else} {/if} ```