getkirby / kql

Kirby's Query Language API combines the flexibility of Kirby's data structures, the power of GraphQL and the simplicity of REST.
https://getkirby.com
MIT License
145 stars 5 forks source link

Query for Previous / Next Sibling Entry #23

Closed maxfrischknecht closed 3 years ago

maxfrischknecht commented 3 years ago

I'm trying to query for the next/prev sibling entry on a page like so:

const response = await $axios.post('api/query', {
    query: "page('projects/" + params.slug + "')",
        select: {
            title: true,
            nextProject: {
                query: 'page.next'
            }
        }
    )}
)}

It basically works an returns the whole page as an object:

entries:  {
    children: [],     
    content: {
        title: 'test',
       // all the other fields
    }
}  

However, when I try to specify the query, for example like below, I get an error.

const response = await $axios.post('api/query', {
    query: "page('projects/" + params.slug + "')",
        select: {
            title: true,
            nextProject: {
                query: 'page.next',
                select: {
                    title: true,
                    previewImage: {
                        query: 'page.previewImage.toFile'
                    }
                }
            }
        }
    )}
)}

I'm sure this is only a question of writing the query correctly, but since there is no documentation regarding this, I'm currently lost and appreciate all tipps & helps.

lukasbestle commented 3 years ago

Which error do you get with the second query?

maxfrischknecht commented 3 years ago

Somehow it started working at some point. The problem was probably elsewhere 🤔. However, for future reference, this works:

const response = await $axios.post('api/query', {
    query: "page('projects/" + params.slug + "')",
        select: {
            title: true,
            nextProject: {
                query: 'page.next',
                select: {
                    title: true,
                    previewImage: {
                        query: 'page.previewImage.toFile'
                    }
                }
            }
        }
    )}
)}