GraphQLReturnType<T>: T extends Record<string, unknown>
    ? {
        [K in keyof T]?: GraphQLReturnType<T[K]>
    }
    : T

Accepts a code generated model type and returns a supertype that can accept return values from the relevant graphql operations.

For example:

import { GraphQLReturnType } from 'aws-amplify/api';
import { MyModel } from './API';
import { getMyModel } from './graphql/queries';

const [item, setItem] = useState<GraphQLReturnType<MyModel>>();
setItem(await client.graphql({ query: getMyModel }).data.getMyModel!)

Trying to assign the result of a getMyModel operation directly to a MyModel variables won't necessarily work, because normally-required related models might not be part of the selection set.

This util simply makes related model properties optional recursively.

Type Parameters

  • T