Fix Directus GraphQL queries for content_pages and projects
Co-authored-by: denshooter <44590296+denshooter@users.noreply.github.com>
This commit is contained in:
@@ -142,14 +142,19 @@ export async function getContentPage(
|
||||
const query = `
|
||||
query {
|
||||
content_pages(
|
||||
filter: { slug: { _starts_with: "${slug}" } }
|
||||
limit: 25
|
||||
filter: {
|
||||
_and: [
|
||||
{ slug: { _eq: "${slug}" } },
|
||||
{ locale: { _eq: "${directusLocale}" } }
|
||||
]
|
||||
}
|
||||
limit: 1
|
||||
) {
|
||||
id
|
||||
slug
|
||||
locale
|
||||
title
|
||||
content
|
||||
status
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -161,11 +166,28 @@ export async function getContentPage(
|
||||
);
|
||||
|
||||
const pages = (result as any)?.content_pages || [];
|
||||
if (pages.length === 0) return null;
|
||||
if (pages.length === 0) {
|
||||
// Try without locale filter
|
||||
const fallbackQuery = `
|
||||
query {
|
||||
content_pages(
|
||||
filter: { slug: { _eq: "${slug}" } }
|
||||
limit: 1
|
||||
) {
|
||||
slug
|
||||
locale
|
||||
title
|
||||
content
|
||||
status
|
||||
}
|
||||
}
|
||||
`;
|
||||
const fallbackResult = await directusRequest('', { body: { query: fallbackQuery } });
|
||||
const fallbackPages = (fallbackResult as any)?.content_pages || [];
|
||||
return fallbackPages[0] || null;
|
||||
}
|
||||
|
||||
// Prefer exact locale, otherwise fall back to first available
|
||||
const exact = pages.find((p: any) => p.locale === directusLocale);
|
||||
return exact || pages[0];
|
||||
return pages[0];
|
||||
} catch (error) {
|
||||
console.error(`Failed to fetch content page ${slug} (${locale}):`, error);
|
||||
return null;
|
||||
@@ -443,12 +465,11 @@ export async function getProjects(
|
||||
const filters = ['status: { _eq: "published" }'];
|
||||
|
||||
if (options?.featured !== undefined) {
|
||||
filters.push(`featured: { _eq: ${options.featured} }`);
|
||||
filters.push(`featured: { _eq: ${options.featured ? 1 : 0} }`);
|
||||
}
|
||||
|
||||
if (options?.published !== undefined) {
|
||||
filters.push(`published: { _eq: ${options.published} }`);
|
||||
}
|
||||
// Remove published filter since it doesn't exist in Directus schema
|
||||
// The status field already handles published/draft state
|
||||
|
||||
if (options?.category) {
|
||||
filters.push(`category: { _eq: "${options.category}" }`);
|
||||
@@ -474,7 +495,7 @@ export async function getProjects(
|
||||
projects(
|
||||
${filterString}
|
||||
${limitString}
|
||||
sort: ["-featured", "-created_at"]
|
||||
sort: ["-featured", "-date_created"]
|
||||
) {
|
||||
id
|
||||
slug
|
||||
@@ -482,16 +503,14 @@ export async function getProjects(
|
||||
difficulty
|
||||
tags
|
||||
technologies
|
||||
github_url
|
||||
live_url
|
||||
github
|
||||
live
|
||||
image_url
|
||||
demo_video_url
|
||||
performance_metrics
|
||||
screenshots
|
||||
featured
|
||||
published
|
||||
demo_video
|
||||
date_created
|
||||
date_updated
|
||||
featured
|
||||
status
|
||||
translations {
|
||||
title
|
||||
description
|
||||
@@ -534,14 +553,14 @@ export async function getProjects(
|
||||
challenges: trans.challenges,
|
||||
lessons_learned: trans.lessons_learned,
|
||||
future_improvements: trans.future_improvements,
|
||||
github_url: proj.github_url,
|
||||
live_url: proj.live_url,
|
||||
github_url: proj.github,
|
||||
live_url: proj.live,
|
||||
image_url: proj.image_url,
|
||||
demo_video_url: proj.demo_video_url,
|
||||
demo_video_url: proj.demo_video,
|
||||
performance_metrics: proj.performance_metrics,
|
||||
screenshots: proj.screenshots || [],
|
||||
featured: proj.featured || false,
|
||||
published: proj.published || false,
|
||||
featured: proj.featured === 1 || proj.featured === true,
|
||||
published: proj.status === 'published',
|
||||
created_at: proj.date_created,
|
||||
updated_at: proj.date_updated
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user