After running a GraphQL query, I receive a nested object where the query name serves as the first-level key and the actual data is located on the second level:
{
getProduct: {
id: "1",
name: "test",
}
}
Within my query function, I have set it up to automatically extract the first key of the object and return the value of getProduct
. However, I am looking for a way to determine the type of the first key as the return value of the query function.
type QueryReturn = FirstElement<GetProductQuery>; // should be { id: string; name: string }
All of the solutions I've come across online focus on inferring the Head or Tail of an Array or Function.