> For the complete documentation index, see [llms.txt](https://doc.demarches-simplifiees.fr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.demarches-simplifiees.fr/api-graphql/pagination.md).

# Pagination

Basée sur un système de curseur

La pagination sur l’API GraphQL se fait par « curseur ». Nous vous renvoyons à la définition faite par Microsoft d'un curseur : <https://learn.microsoft.com/fr-fr/office/client-developer/access/desktop-database-reference/what-is-a-cursor>

> Le curseur est ainsi nommé car il indique la position active dans le jeu de résultats, à l'instar du curseur de l'écran de votre ordinateur.

Concrètement, nous suivons la spec relay : <https://relay.dev/graphql/connections.htm>. Pour récupérer la prochaine page il faut passer à l’API le « curseur » de la fin de la page précédente.

## Application concrète

### Première requête

Voici un exemple. On commence par faire une query pour récupérer les 100 premiers dossiers :

```graphql
query getDemarche($demarcheNumber: Int!, $after: String) {
  demarche(number: $demarcheNumber) {
    dossiers(first: 100, after: $after) {
      pageInfo {
        endCursor
        hasNextPage
      }
      nodes {
        id
        number
      }
    }
  }
}
```

```graphql
{
  "query": <query>,
  "operationName": "getDemarche",
  "variables": {
    "demarcheNumber": 1234
  }
}
```

Dans le résultat obtenu il faut lire la valeur du « curseur » dans le champ `demarche.dossiers.pageInfo.endCursor` .

### Deuxième requête, et toutes les autres :

On peut passer alors ce « curseur » comme argument `after` dans la prochaine query. Et ainsi de suite jusqu’à ce que le champ `demarche.dossiers.pageInfo.hasNextPage` soit égal à `false`.

```graphql
query getDemarche($demarcheNumber: Int!, $after: String) {
  demarche(number: $demarcheNumber) {
    dossiers(first: 100, after: $after) {
      pageInfo {
        endCursor
        hasNextPage
      }
      nodes {
        id
        number
      }
    }
  }
}
```

```graphql
{
  "query": <query>,
  "operationName": "getDemarche",
  "variables": {
    "demarcheNumber": 1234,
    "after" "abc"
  }
}
```

Pour un exemple d'implémentation, rendez-vous sur :

{% content-ref url="/pages/GNOklohkEcVwPcYXWSB8" %}
[Pagination – Récupérer tous les dossiers d'une démarche](/api-graphql/cas-dusages-exemple-dimplementation/pagination-recuperer-tous-les-dossiers-dune-demarche.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://doc.demarches-simplifiees.fr/api-graphql/pagination.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
