I've been exploring ways to enhance safety in my client-side GraphQL queries, and I'm open to suggestions for a better approach.
Currently, my query is structured like this:
export const tenantManagePageQuery = async (tenantId: string) =>
graphQLClient.request<{
tenants: TenantManagePageQueryTenant[];
}>(
/* GraphQL */ `
query tenants($tenantId: String!) {
tenants(tenantIds: [$tenantId]) {
id
description
name
approvedUsers {
id
alias
}
pendingUsers {
id
alias
}
}
}
`,
{ tenantId },
);
To define the TenantManagePageQueryTenant
type, I usually do something similar to this:
interface TenantManagePageQueryTenant
extends Pick<Tenant, 'id' | 'description' | 'name'> {}
The base Tenant model represents my GQL model type.
I'm wondering if there is a way to extend the `Pick` statement to also include nested properties.
For instance:
interface TenantManagePageQueryTenant
extends Pick<Tenant, 'id' | 'description' | 'name' | Pick<approvedUser| 'id' | 'alias'> {}