8000 README update, moved pagination content to /pagination/README.md · jxmot/github-graphql-snippets@8c4ff35 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c4ff35

Browse files
committed
README update, moved pagination content to /pagination/README.md
1 parent f0b458f commit 8c4ff35

File tree

1 file changed

+1
-85
lines changed

1 file changed

+1
-85
lines changed

README.md

Lines changed: 1 addition & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -196,91 +196,7 @@ And here is the result of the query:
196196

197197
### Queries and Pagination
198198

199-
It took me a bit to understand how *pagination* works under the GitHub's implementation of GraphQL. Honestly it isn't that difficult. But the available documentation does not seem to provide any *workable* examples or a very clear explanation.
200-
201-
The GitHub GraphQL uses the *Complete Connection Model* method of pagination. Which is partially descrbed [here](https://graphql.github.io/learn/pagination/#complete-connection-model).
202-
203-
Pagination Examples:
204-
205-
* **`/queries/user-verified-pagination-starred_repos.graphql`** : retrieves the validated user's list of starred repos where pagination can applied.
206-
207-
#### Pagination in Detail
208-
209-
Using the **`/queries/user-verified-pagination-starred_repos.graphql`** file I will attempt to explain how pagination works under the GitHub GraphQL API.
210-
211-
First, open a GraphQL *explorer*. This example should also work with GitHub's [GraphQL Explorer](https://docs.github.com/en/free-pro-team@latest/graphql/overview/explorer). Open the Explorer and *paste* the following into it:
212-
213-
The query:
214-
215-
```
216-
query($fst:Int, $lst:Int, $aft:String, $bef:String) {
217-
viewer {
218-
login
219-
name
220-
starredRepositories(orderBy: {direction: DESC, field: STARRED_AT},
221-
first: $fst,
222-
last: $lst,
223-
after: $aft,
224-
before: $bef) {
225-
totalCount
226-
pageInfo {
227-
hasNextPage
228-
endCursor
229-
hasPreviousPage
230-
startCursor
231-
}
232-
edges {
233-
starredAt
234-
node {
235-
name
236-
stargazerCount
237-
primaryLanguage {
238-
name
239-
color
240-
}
241-
}
242-
}
243-
}
244-
}
245-
}
246-
```
247-
248-
Variables needed by the query, paste this into the *query variables* pane :
249-
250-
```
251-
{
252-
"fst": 3,
253-
"lst": null,
254-
"aft": null,
255-
"bef": null
256-
}
257-
```
258-
259-
To see how pagination works use these steps:
260-
261-
1) Run the query with the data as shown below
262-
2) After the successful query, copy the string from the
263-
result at `pageInfo.endCursor` into the `aft` data item
264-
3) Run the query again
265-
4) The next "page" will be returned
266-
267-
Steps 2 - 4 can be repeated until `pageInfo.hasNextPage`
268-
becomes `false`.
269-
270-
5) To go to the previous page copy the string from the result
271-
at `pageInfo.startCursor` into the `bef` data item
272-
6) Set `aft` to `null`
273-
7) Set `fst` to `null`
274-
8) Set `lst` to 3
275-
9) Run the query again
276-
10) The previous "page" will be returned
277-
278-
Steps 6 - 9 can be repeated until `pageInfo.hasPreviousPage`
279-
becomes `false`.
280-
281-
**NOTE**: You will need to have some starred repositories under your account. The minimum recommended for this demonstration is 12. If you have a lot of starred repos change the value used in `"fst"` and `"lst"` to a larger value. For example, if you had 100 starred repos you could change that value from `3` to `25`. That would give you 4 pages of 25 items.
282-
283-
For a *visual* representation of pagination view this [file](http://webexperiment.info/ghqlpagination/pagination.html). There is also an accompanying Excel spreadsheet in the `docs` folder in this repository.
199+
This described in detail [here](./pagination/README.md)
284200

285201
## Mutations
286202

0 commit comments

Comments
 (0)
0