1

How do I turn these Craft queries into a GraphQL one?

// entry.twig

entry.getPrev({ section: "contentHub" })
entry.getNext({ section: "contentHub" })

I want to get the previous and next entry using the current entry

3

So I'm wondering the same thing, I'm using CraftQL as I need to support mutations, and I am close with this - but I get an error if I try to use $id instead of a hard-wired Int (e.g. 99):


query getEntryData($id: [Int]) {
  prevEntry: entry(prevSiblingOf: 99) {
    id
    title
    slug
    uri
  }
  nextEntry: entry(nextSiblingOf: 99) {
    id
    title
    slug
    uri
  }
  entryData: entry(section: investigations, id: $id) {
    id
    title
    slug
    uri
  }
}

I get the following error:

"message": "Variable \"$id\" of type \"[Int]\" used in position expecting type \"Int\".",

BUT then if I pass the $id as Int (and not [Int]) it works. Can't explain the typing difference.

query getEntryData($id: [Int], $sameId: Int) {

   prev:entry(prevSiblingOf: $sameId) {
    id
    title
    slug
    uri
  }
  next: entry(nextSiblingOf: $sameId) {
    id
    title
    slug
    uri
  }
  investigation: entry(section: investigations, id: $id) {
    id
    title
    slug
    uri
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.