Another question - I have a Project model and I wi...
# prisma-whats-new
h
Another question - I have a Project model and I will need simple pagination to next and previous projects. Can these be queried through qgl, or do I have to query all the Projects and use that?
n
@hellojere pagination comes out of the box at Graphcool, have a look here: https://www.graph.cool/docs/reference/simple-api/pagination-ojie8dohju
h
Thanks, will try to work it out from here!
n
Sure let me know if you need additional help
h
Ok, I can get the next or the previous, but how to combine them into one query? And do I need the ID always, or can I query with another field like
slug
?
Copy code
query {
  allProjects(
    first: 2,
    after: "cj0ta59xbqapc01041ihfw3fk"
  ) {
    id
    title
  }
}
Thanks for helping out, really
n
Sure it's a pleasure ๐Ÿ™‚
So you can only use
first
and
after
OR
last
and
before
. But if you need to query "around" a specific ID, you could do that:
Copy code
query {
  after: allProjects(
    first: 2,
    after: "cj0ta59xbqapc01041ihfw3fk"
  ) {
    id
    title
  }
before: allProjects(
    last: 2,
    before: "cj0ta59xbqapc01041ihfw3fk"
  ) {
    id
    title
  }
}
and yep, currently it's only possible to use ID, however you can query a project id by slug:
Copy code
query {
  Project(slug: "some-slug") {
    id
  }
}
h
Ok, thanks. Will use the playground a little!
๐Ÿ‘ 1
One more to specify. Is it possible to make a variable from the first query, and use it underneath?
Copy code
query {
  Project(slug: "test") {
    id
  }
  nextProject: allProjects(
    first: 1,
    after: "cj0ta59xbqapc01041ihfw3fk"
  ) {
    id
    title
  }
  previousProject: allProjects(
    last: 1,
    before: "cj0ta59xbqapc01041ihfw3fk"
  ) {
    id
    title
  }
}
n
nope that's not possible with GraphQL. you would need to use two separate queries
to be clear, instead of
cj0ta59xbqapc01041ihfw3fk
you would want the result of
Project(slug: "test")
, right?
h
Yes
Thatโ€™s fine though, time to learn some new things then. The lazy loading approach should be good here
๐Ÿ‘ 1