Solved

Return to more than 50 cards

  • 24 August 2020
  • 6 replies
  • 935 views

Userlevel 5

Does allCards return more than 50 cards per query, or do we need to pass the ""first"" combined with ""after"" parameters?

icon

Best answer by Marcos Carvalho 24 August 2020, 15:22

View original

6 replies

Userlevel 6
Badge +6

Hey Nigel, 

 

Pipefy GraphQL API has a maximum limit of 50 objects for each request, but you can request less objects using the filter first.  allCards query has this limitation and it’s necessary to pass the parameters for Pagination.

 

Here a pagination example:

 

In each request you can query the pageInfo to bring the cursor for the next (or previous) list of 50 objects. 

 

{
allCards(pipeId: 1264926,first:5) {
edges {
node {
id
}
}
pageInfo {
endCursor
startCursor
}
}
}

 

Here an example payload for the request:

{
"data": {
"allCards": {
"edges": [
{
"node": {
"id": "368825599"
}
},
{
"node": {
"id": "369521028"
}
},
{
"node": {
"id": "373362189"
}
},
{
"node": {
"id": "373362192"
}
},
{
"node": {
"id": "375141382"
}
}
],
"pageInfo": {
"endCursor": "WyIxLjAiLCIyOC4wIiwzNzUxNDEzODJd",
"startCursor": "WyIxLjAiLCIzLjAiLDM2ODgyNTU5OV0"
}
}
}
}

 

 

Now you can use the startCursor for the next 5 objects:

 

{
allCards(pipeId: 1264926,first:5,after:"WyIxLjAiLCIzLjAiLDM2ODgyNTU5OV0") {
edges {
node {
id
}
}
pageInfo {
endCursor
startCursor
}
}
}

 

 

 

Hope it helps you. 

 

 

Userlevel 5

@Marcos Carvalho That was fast! 

 

Thanks!!! 

Userlevel 2

 

Hi Marcos,
If we want to search for the next records using the "after", wouldn't it be correct to use the endCursor field instead of the startCursor ? I believe that the startCursor should be used if you want to go backwards using the "before". ???

Userlevel 7
Badge +8

@jpneumann empirically, I can confirm that Marcos’s solution is the correct one. I too had my issues first as intuitively I would have expected it the other way round, but in this case at least, this is how it is implemented.

Userlevel 2


Hi @genietim,

 

After posting these questions, I developed pagination routines using @Marcos Carvalho  recommendation and the way I thought it would be correct. 

 

The way @Marcos Carvalho  suggested, it even worked, but bringing duplicate records and consuming much more time and GraphQL requests. As I suggested, it was the way it worked correctly.

 

When we want to advance the pagination to the next records, we use endCursor + after. When we want to return to the previous records we use startCursor + before. See the following example:

 

 

{"query":"{ organizations { tables(first:10) { edges { cursor } pageInfo { startCursor endCursor hasNextPage hasPreviousPage } } } }"}

 

This query will return the cursor of the first 10 tables of an organization:

 

 

{
    "data": {
        "organizations": [
            {
                "tables": {
                    "edges": [
                        {
                            "cursor": "MQ"
                        },
                        {
                            "cursor": "Mg"
                        },
                        {
                            "cursor": "Mw"
                        },
                        {
                            "cursor": "NA"
                        },
                        {
                            "cursor": "NQ"
                        },
                        {
                            "cursor": "Ng"
                        },
                        {
                            "cursor": "Nw"
                        },
                        {
                            "cursor": "OA"
                        },
                        {
                            "cursor": "OQ"
                        },
                        {
                            "cursor": "MTA"
                        }
                    ],
                    "pageInfo": {
                        "startCursor": "MQ",
                        "endCursor": "MTA",
                        "hasNextPage": true,
                        "hasPreviousPage": false
                    }
                }
            }
        ]
    }
}

 

Note that the first cursor is "MQ" and the last is "MTA", as returned in pageInfo: "startCursor": "MQ" and "endCursor": "MTA" .

 

Now let's make a pagination of 3 in 3 records:

 

{"query":"{ organizations { tables(first:3) { edges { cursor } pageInfo { startCursor endCursor hasNextPage hasPreviousPage } } } }"}

 

In this case, for the example above, the records with cursor "MQ", "Mg" and "Mw" must be returned

 

Executing the query, we have the following result:

 

{
    "data": {
        "organizations": [
            {
                "tables": {
                    "edges": [
                        {
                            "cursor": "MQ"
                        },
                        {
                            "cursor": "Mg"
                        },
                        {
                            "cursor": "Mw"
                        }
                    ],
                    "pageInfo": {
                        "startCursor": "MQ",
                        "endCursor": "Mw",
                        "hasNextPage": true,
                        "hasPreviousPage": false
                    }
                }
            }
        ]
    }
}

 

Confirming our initial expectations.

 

Now we want to search for the next 3 records, which, according to our initial example, should return the cursors after "Mw", which are: "NA", "NQ" and "Ng" .

 

For this we will use the "after" option and as a value we will use "endCursor", because we want the next 3 records after the last cursor, which in this case is "Mw":

 

{"query":"{ organizations { tables(first:3, after:\"Mw\") { edges { cursor } pageInfo { startCursor endCursor hasNextPage hasPreviousPage } } } }"}

 

The result will be:

 

{
    "data": {
        "organizations": [
            {
                "tables": {
                    "edges": [
                        {
                            "cursor": "NA"
                        },
                        {
                            "cursor": "NQ"
                        },
                        {
                            "cursor": "Ng"
                        }
                    ],
                    "pageInfo": {
                        "startCursor": "NA",
                        "endCursor": "Ng",
                        "hasNextPage": true,
                        "hasPreviousPage": false
                    }
                }
            }
        ]
    }
}

 

That is, we obtained exactly the next expected records: "NA", "NQ" and "Ng".

 

If in this case we used the startCursor + after, as suggested by @Marcos Carvalho, the next 3 records  returned after "MQ" that would be "Mg", "Mw" and "NA", which is wrong because I will return records that we have already get before and that I wouldn’t need to bring any more.

 

Finally, I hope that I was didactic enough to explain my understanding of how pagination should be carried out.

Userlevel 7
Badge +8

@jpneumann yes, you are right, I just checked again, sorry for my comment, I had something wrong in mind.

Reply