Make GraphQL queries more compact

This commit is contained in:
2022-08-16 21:17:14 +02:00
parent 52e0407700
commit 0e6aaaa4e2
14 changed files with 435 additions and 471 deletions

View File

@@ -7,35 +7,33 @@ import { getRandomItem } from '$utils/functions'
export const load: PageServerLoad = async ({}) => {
try {
// Get content from API
const data = await fetchAPI(`
query {
posters: product (
filter: { status: { _eq: "published" }}
) {
const data = await fetchAPI(`query {
posters: product (
filter: { status: { _eq: "published" }}
) {
name
type
description
details
location {
name
type
description
details
location {
name
slug
slug
}
product_id
photos_product {
directus_files_id {
id
title
}
product_id
photos_product {
directus_files_id {
id
title
}
}
photos_preview {
directus_files_id {
id
title
}
}
photos_preview {
directus_files_id {
id
title
}
}
}
`)
}`)
if (data) {
const randomPoster = getRandomItem(data.data.posters)