Make GraphQL queries more compact
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user