We are getting a list of news items from payload using the rest API which returns the below JSON.
When we use the keyword
payload generate:types
it doesn't include a root type for the docs array.
We've managed to get around it by providing a news root type as shown below. Is there any way to not have to do this? We have a lot of collections of data we need to fetch.
News root type we have created
export interface NewsRoot {
docs: News[]
}
News type generated by payload
export interface News {
id: string;
newsTitle: string;
newsSubtitle?: string;
tags?: string[] | Tag[];
publishDate: string;
newsBackgroundImage?: string | Media;
newsDescription: {
[k: string]: unknown;
}[];
createdAt: string;
updatedAt: string;
}
News Response JSON
{
"docs":[
{
"id":"63eadb6fa2e0dc97541772fd",
"newsTitle":"Example News Post",
"newsSubtitle":"Example subtitle ",
"tags":[
{
"id":"63e97b49dbd275c70ad55f3a",
"tagName":"Tag 1",
"createdAt":"2023-02-12T23:50:33.844Z",
"updatedAt":"2023-02-12T23:50:33.844Z"
},
{
"id":"63e97a64a6d0765b19b75cd1",
"tagName":"Tag 2",
"createdAt":"2023-02-12T23:46:44.215Z",
"updatedAt":"2023-02-12T23:46:44.215Z"
}
],
"publishDate":"2023-02-13T11:00:00.000Z",
"newsDescription":[
{
"children":[
{
"text":"Example news post"
}
]
}
],
"createdAt":"2023-02-14T00:53:03.082Z",
"updatedAt":"2023-02-15T03:57:21.638Z"
}
],
"totalDocs":1,
"limit":10,
"totalPages":1,
"page":1,
"pagingCounter":1,
"hasPrevPage":false,
"hasNextPage":false,
"prevPage":null,
"nextPage":null
}
Hi @MRL - we will definitely include this in our future updates to
generate:types
, I've made a note on a related github discussion that you can find here
https://github.com/payloadcms/payload/discussions/2090Thanks @jesschow. I will keep an eye out for a future update 🙂
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.