|
| 1 | +# Lists |
| 2 | + |
| 3 | +This documentation will explain how to create lists, using GraphQL requests and Vue.js mixins. |
| 4 | + |
| 5 | +## API |
| 6 | + |
| 7 | +### Use case and result iterator |
| 8 | + |
| 9 | +It starts by creating a use case. |
| 10 | +For instance, [src/api/src/UseCase/User/GetUsers](../src/api/src/UseCase/User/GetUsers.php). |
| 11 | + |
| 12 | +Your use case have to return a `ResultIterator` to paginate efficiently your results. |
| 13 | +Let's take a look at the GraphQL query for the [GetUsers](../src/api/src/UseCase/User/GetUsers.php) use case: |
| 14 | + |
| 15 | +```graphql |
| 16 | +query users($search: String, $role: Role, $sortBy: UsersSortBy, $sortOrder: SortOrder, $limit: Int!, $offset: Int!) { |
| 17 | + users(search: $search, role: $role, sortBy: $sortBy, sortOrder: $sortOrder) { |
| 18 | + items(limit: $limit, offset: $offset) { |
| 19 | + id |
| 20 | + firstName |
| 21 | + lastName |
| 22 | + email |
| 23 | + locale |
| 24 | + role |
| 25 | + } |
| 26 | + count |
| 27 | + } |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +The `limit` and `offset` parameters from the `items` part do not exist in the use case parameters; |
| 32 | +it is the `ResultIterator` that takes these parameters. |
| 33 | + |
| 34 | +Also, note the `count` value; that's the total of items. |
| 35 | + |
| 36 | +We will see later how to use these values to create a pagination on the web application. |
| 37 | + |
| 38 | +### Enumerators |
| 39 | + |
| 40 | +For "sort by" and "sort order" values, we use enumerators |
| 41 | +(see [src/api/src/Domain/Enum/Filter](../src/api/src/Domain/Enum/Filter)). |
| 42 | + |
| 43 | +GraphQLite recognizes an enumerator as a valid value for your GraphQL request. |
| 44 | + |
| 45 | +Each enumerator's key (i.e., `FIRST_NAME`) is a GraphQL value, while each enumerator's value (i.e., `first_name`) |
| 46 | +is valid SQL expression. |
| 47 | + |
| 48 | +See `search` method in [src/api/src/Domain/Dao/UserDao](../src/api/src/Domain/Dao/UserDao.php) for an example of usage. |
| 49 | + |
| 50 | +## Web application |
| 51 | + |
1 | 52 | IF default TEXT filters === null, it will refresh the page the first time!!
|
2 | 53 |
|
3 | 54 | CLIENT need to try catch and call this.$nuxt.error
|
4 |
| -SERVER need to try catch and call context.error |
| 55 | +SERVER need to try catch and call context.error |
| 56 | + |
| 57 | +--- |
| 58 | + |
| 59 | +[Back to top](#lists) - [Home](../README.md) |
0 commit comments