Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda