Skip to content

Commit 852f2ef

Browse files
author
Julien Neuhart
committed
WIP lists documentation, minor typo in users GraphQL query
1 parent 209ffef commit 852f2ef

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

Diff for: docs/lists.md

+56-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,59 @@
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+
152
IF default TEXT filters === null, it will refresh the page the first time!!
253

354
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)

Diff for: src/webapp/services/queries/users/users.query.gql

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ query users($search: String, $role: Role, $sortBy: UsersSortBy, $sortOrder: Sort
44
id
55
firstName
66
lastName
7-
email,
8-
locale,
7+
email
8+
locale
99
role
1010
}
1111
count

0 commit comments

Comments
 (0)