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!