Possible Bug - GraphQL - Cursor Unexpected Behavior

Hola !

I'm trying to build a next & previous CTA's in the detail view/page with my custom document type yoga_sutra so user can go to the next or previous entry... I was following this documentation Query Data with GraphQL - Prismic, and everything was working fine until I notice the following and unexpect behavior, I don't know if it is my understanding or the API which is wrong so maybe someone can point what I'm doing wrong, so here it is what's I'm doing:

If I use allYoga_sutras to query all items of my custome type, I get two differents entries with two cursors as shown in the below image which is seems fine and expected from the API.

My understanding based on documentation, is that using the cursor in combination with the before or after options, the query will return the previous/next item to that cursor, and that works fine:

Using the first cursor, I only get the next item, which is expected.

Using the second cursor, I only get the previous item, which is also expected

But here is where things start to go weird, if I retrieve the second item using it's ID, it returns all the information that belongs to it, but the cursor is the cursor of the first item (which I think is a bug):

So when all of this queries are used by my Next App, in the second entry it return the cursor of the first item and display the next entry of the first item which is wrong, it should display only the prev entry.

Thanks in advance.

1 Like

Hola Victor, welcome to the forum!!

You're right, that doesn’t seem correct. I couldn’t tell what's the issue just by sight. Could you share with me the URL of your repo so I can test on my side? If you prefer, you can send me this info via private dm

1 Like

I'm also sharing here the GraphQL pagination example we have available:

Live demo

[Update] The cursor should be seen as an index 0, 1, 3, 4, and so on... So the position of the document for a specific query. It isn't based on the docs IDs

hey @Pau thanks for the update, now it makes sense.

So when I run a query, each cursor returned represent an index at that set of items, example:

And that's the reason why when I query for the third document it always return with the "cursor of the first item", and is because that cursor represent index 0 and not belongs to any document.

Thanks for the suppor!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.