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

@@ -159,38 +159,36 @@
const loadPhotos = async (page: number) => {
const res = await fetch('/api/data', {
method: 'POST',
body: `
query {
photos: photo (
filter: {
${filterCountry !== 'all' ? `location: { country: { slug: { _eq: "${filterCountry}" }} },` : ''}
status: { _eq: "published" },
},
sort: "${filterSort === 'latest' ? '-' : ''}date_created",
limit: ${PUBLIC_GRID_INCREMENT},
page: ${page},
) {
body: `query {
photos: photo (
filter: {
${filterCountry !== 'all' ? `location: { country: { slug: { _eq: "${filterCountry}" }} },` : ''}
status: { _eq: "published" },
},
sort: "${filterSort === 'latest' ? '-' : ''}date_created",
limit: ${PUBLIC_GRID_INCREMENT},
page: ${page},
) {
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
}
city
}
`,
}`,
})
const { data: { photos }} = await res.json()