Im using nextjs app with contentful and grapqhl, In general im trying to get all my Entries for a specific content type but for some reason i dont get it full, some are missing and i need to publish and unpublish the entries in order to get them. but prob some miss doing this.
Im doing something like this
async function getApps(
pageSkip = 0,
itemLimit = 1000,
entries: AppSitemapFragment[] = []
): Promise<AppSitemapFragment[]> {
try {
const { marketplaceAppCollection } = await client().request(AppsSitemapDocument, {
limit: itemLimit,
skip: pageSkip,
where: { slug_exists: true }
})
if (!marketplaceAppCollection) return entries
const { skip, limit, total, items } = marketplaceAppCollection
entries.push(...items.filter(isNonNullable))
if (total > limit * (skip + 1)) {
return entries.concat(await getApps(skip + 1, limit))
}
} catch (e) {
console.log(e)
}
return entries
}
In this case Client is my contentful client.
import { GraphQLClient } from 'graphql-request'
type Args = {
preview?: boolean
}
export const client = ({ preview }: Args = {}) => {
return new GraphQLClient(
`https://graphql.contentful.com/content/v1/spaces/${process.env.NEXT_PUBLIC_CONTENTFUL_SPACE_ID}/environments/${process.env.NEXT_PUBLIC_CONTENTFUL_ENVIRONMENT}`,
{
headers: {
Authorization: `Bearer ${
Boolean(preview)
? process.env.NEXT_PUBLIC_CONTENTFUL_PREVIEW_TOKEN
: process.env.NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN
}`
}
}
)
}
Do you have any Idea why this could happends?
Also this is my graphql
fragment AppSitemap on MarketplaceApp {
sys {
publishedAt
}
slug
seoMetadata {
noindex
nofollow
}
}
query AppsSitemap(
$where: MarketplaceAppFilter = { slug_exists: true }
$limit: Int = 1000
$skip: Int = 0
$locale: String
) {
marketplaceAppCollection(where: $where, limit: $limit, skip: $skip, locale: $locale) {
total
skip
limit
items {
...AppSitemap
}
}
}