Hi everyone, I’m having a weird issue when implem...
# orm-help
m
Hi everyone, I’m having a weird issue when implementing pagination with the after and first attributes, the results always have duplicates for instance if i fetch the first the first 15 records and then fetch another 15 after them i ended up having 5 or more from the previous query in the second one even though the id for the end cursor was the last record that was returned, and if I Lower the number of record to 10 it happens but not always
j
after: x
really means
where id > x
– you're sorting your results by date and not by ID, so that's probably not gonna work for you!
assume you have this data (sorted by date desc):
Copy code
[
  { "id": "1", "date": "2019" },
  { "id": "9", "date": "2018" },
  { "id": "5", "date": "2013" },
  { "id": "6", "date": "2009" },
  { "id": "2", "date": "1992" },
  { "id": "7", "date": "1980" }
]
first: 3
gives you:
Copy code
[
  { "id": "1", "date": "2019" },
  { "id": "9", "date": "2018" },
  { "id": "5", "date": "2013" },
]
then
first: 3, after: 5
has to give you:
Copy code
[
  { "id": "9", "date": "2018" },
  { "id": "6", "date": "2009" },
  { "id": "7", "date": "1980" }
]
maybe adding
id_gt
to your
where
clause would work?
(and get rid of
after
!)
m
@Akira Laine thanks for your explanation, but id_gt didn’t do it still gets alot of duplicates
j
sorry – that gives you the same issue as
after
! I meant
date_gt
m
this should be the right query resolver right
return context.prisma.jobs( { where: { date_gt: args.after, OR: [ { description_contains: filter }, { title_contains: filter }, { employer_contains: filter }, { url_contains: filter } ] }, orderBy: ‘date_DESC’, first: args.first }, info )
this makes it repeats the same data over and over again
j
date_gt needs to have the value of the greatest date from the previous page
because you're sorting by date, you need to paginate by it too!
m
yeah am passing the date of the last record
j
🤔 possibly
date_lt
, to match the sort order
m
@Jacob nailed it, thanks a lot
j
🙌 kudos