Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

242
Vistas
Can I use the graphql pagination cursor as an unique indentifier?

The main question is in the topic basically but I'd like to describe the problem in a bit details.

I'm working on the Apollo graphql pagination which is cursor-based and in my Cache, I should define the merge function to combine the existing and incoming data. Every data object has the common graphql pagination structure:

{
        "totalCount": ...,
        "pageInfo": {
            "startCursor": "...",
            "endCursor": "...",
            "hasNextPage": true,
            "__typename": "..."
        },
        "edges": [...],
}

I need to override the existing data like: pageInfo, totalCount, etc. by the same properties from the incoming but in the case of edges I need to carefully merge the existing and incoming items. To make it more elegant and to avoid duplicates I'd like to iterate over the incoming items and check if every item is unique. eg. if the existing edges don't contain items that exist in the incoming.

So I'm wondering if I can use the graphql pagination cursor that exists in every node as a comparison argument. I know that I can use the Item's ID but if it's possible to use the Cursor value as well, I could avoid to using the deeper property level of the edge's item

Here is an example of the data structure:

{
    "listArticles": {
        "totalCount": 22,
        "pageInfo": {
            "startCursor": "NjE2N2ZlMmI4N2NiNDczMGY0N2U5MGQ5",
            "endCursor": "NjE2ZDkzYTg0NDA5MWYyN2E0MmFkMGM5",
            "hasNextPage": true,
            "__typename": "PageInfo"
        },
        "edges": [
            {
                "cursor": "NjE2N2ZlMmI4N2NiNDczMGY0N2U5MGQ5",
                "node": {
                    "id": "6167fe2b87cb4730f47e90d9",
                    "commentsThreadId": "6167fe2b87cb4730f47e90d8",
                    "__typename": "Article"
                },
                "__typename": "ArticleEdge"
            },
            {
                "cursor": "NjE2ZDkzYTg0NDA5MWYyN2E0MmFkMGM5",
                "node": {
                    "id": "616d93a844091f27a42ad0c9",
                    "commentsThreadId": "616d93a844091f27a42ad0c8",
                    "__typename": "Article"
                },
                "__typename": "ArticleEdge"
            },
        ],
        "__typename": "ArticleConnection"
    }
}

Thanks for any help!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I wouldn't recommend using cursors as unique identifiers, although they may end up uniquely identifying nodes. They should just be used for what they are: opaque strings used to locate nodes within pages.

As far as I know, depending on their implementation, two nodes cannot share one same cursor, but two cursors could be used for one same node.

I would just go "one level deeper" and use the actual item ids.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda