Skip to content
Developerhome
Sage Distribution and Manufacturing Operations

Long Lists: Paging

  Less than to read

By default, a query is limited to 20 elements.

You can change the default value of elements by using the first clause in the query.

The following table displays an example and the result of creating a long list with a query. Some of the fields displayed are not mandatory and others have been omitted.

{ 
    xtremMasterData{ 
        item{ 
            query (first:50, filter:"{isActive:true}"){ 
                totalCount 
                edges { 
                    node { 
                        id 
                        customers{ 
                            query (first:3){ 
                                edges{ 
                                    node{ 
                                        name 
                                        customer { 
                                            id 
                                        } 
                                    } 
                                } 
                            } 
                        } 
                    }
                } 
            } 
        }
    }
} 
{ 
    "data": { 
        "xtremMasterData": { 
            "item": { 
                "query": { 
                    "totalCount": 53, 
                    "edges": [ 
                        { 
                            "node": { 
                                "isActive": true, 
                                "name": "Capteur pression", 
                                "stockUnit": { 
                                    "name": "each", 
                                    "symbol": "each" 
                                } 
                            } 
                        }, 
                        { 
                            "node": { 
                                        "isActive": true, 
                                        "name": "Capteur haute pression", 
                                        "stockUnit": { 
                                            "name": "each", 
                                            "symbol": "each" 
                                        } 
                                    } 
                                },
                            ]
                        }
                    }
                }
            }
        }

To avoid denial-of-service attacks, the execution time and volume of data sent or returned are limited for GraphQL queries.

To manage exceptionally long lists, you need to use paging techniques. There is an additional set of information that you can put at the pageInfo query level:

{ 
    xtremMasterData { 
        item { 
            query(first: 5, filter: "{isActive:true}") { 
                totalCount 
                pageInfo { 
                    endCursor 
                    hasNextPage 
                    startCursor 
                    hasPreviousPage 
                } 
                edges { 
                    node { 
                        id 
                    } 
                } 
            } 
        } 
    } 
}  
{ 
    "data": { 
        "xtremMasterData": { 
            "item": { 
                "query": { 
                    "totalCount": 53, 
                    "pageInfo": { 
                            "endCursor": "[\"013001\"]#48", 
                            "hasNextPage": true, 
                            "startCursor": "[\"011000\"]#99", 
                            "hasPreviousPage": false 
                        }, 
                    "edges": [ 
                        { 
                            "node": { 
                                "id": "011000" 
                            } 
                        }, 
                        { 
                            "node": { 
                                "id": "011005" 
                            } 
                        },
                    ]
                }
            }
        }
    }
} 

Getting the next page can be obtained by using the after: syntax followed by the endCursor value given in the page returned.

Getting the previous page can be obtained by using the before: syntax followed by the startCursor value given in the page returned.

{ 
    xtremMasterData { 
        item 
        { 
            query(first: 5, filter: "{isActive:true}", after: "[\"013001\"]#48") 
            { 
                totalCount 
                pageInfo { 
                    endCursor 
                    hasNextPage 
                    startCursor 
                    hasPreviousPage 
                } 
                edges { 
                    node { 
                        id 
                    } 
                } 
            } 
        } 
    } 
}  
{ 
    "data": { 
        "xtremMasterData": { 
            "item": { 
                "query": { 
                    "totalCount": 53, 
                    "pageInfo": {
                        "endCursor": "[\"401001\"]#79", 
                        "hasNextPage": true, 
                        "startCursor": "[\"014000\"]#86", 
                        "hasPreviousPage": true 
                    }, 
                    "edges": [ 
                        { 
                            "node": { 
                                "id": "014000" 
                            } 
                        }, 
                        { 
                            "node": { 
                                "id": "14B26RA11402400" 
                            } 
                        },
                    ]
                }
            }
        }
    }
}