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

@@ -11,53 +11,51 @@ export const load: PageServerLoad = async ({ url }) => {
const querySort = url.searchParams.get('sort') || PUBLIC_FILTERS_DEFAULT_SORT
// Query
const res = await fetchAPI(`
query {
photos: photo (
filter: {
${queryCountry !== 'all' ? `location: { country: { slug: { _eq: "${queryCountry}" }}},` : ''}
status: { _eq: "published" },
},
sort: "${querySort === 'latest' ? '-' : ''}date_created",
limit: ${PUBLIC_GRID_AMOUNT},
page: 1,
) {
const res = await fetchAPI(`query {
photos: photo (
filter: {
${queryCountry !== 'all' ? `location: { country: { slug: { _eq: "${queryCountry}" }}},` : ''}
status: { _eq: "published" },
},
sort: "${querySort === 'latest' ? '-' : ''}date_created",
limit: ${PUBLIC_GRID_AMOUNT},
page: 1,
) {
id
title
slug
image {
id
title
}
location {
slug
image {
id
title
}
location {
name
region
country {
slug
name
region
country {
slug
name
flag { id }
}
flag { id }
}
city
date_created
}
country: country (
filter: {
slug: { _eq: "${queryCountry}" },
status: { _eq: "published" },
},
) {
slug
}
# Total
total_published: photo_aggregated ${queryCountry !== 'all' ? `(filter: { location: { country: { slug: { _eq: "${queryCountry}" }}}})` : ''} {
count { id }
}
city
date_created
}
`)
country: country (
filter: {
slug: { _eq: "${queryCountry}" },
status: { _eq: "published" },
},
) {
slug
}
# Total
total_published: photo_aggregated ${queryCountry !== 'all' ? `(filter: { location: { country: { slug: { _eq: "${queryCountry}" }}}})` : ''} {
count { id }
}
}`)
const { data } = res