Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions dbquery/pagination/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,27 @@ To retrieve the first page of a result, the operation is called with `after` omi
Subsequent pages can then be retrieved by setting `after` to the value of `endCursor` from `pageInfo` from the previous request. `first` should be set to the value used in the first request.

This is continued until `hasNextPage` is `false`.

## Try it out!

Deploy the schema from `dbquery/pagination` relative to the repository's root directory:

```
stepzen deploy
```

Run the [sample operations](operations.graphql):

Fetch the first five records:

```
stepzen request -f operations.graphql --operation-name=Customers --var first=5
```

Fetch the next five, the value of `after` is taken from the `endCursor` field of the previous request:

```
stepzen request -f operations.graphql --operation-name=Customers --var first=5 --var after="eyJjIjoiTDpRdWVyeTpjdXN0b21lcnMiLCJvIjo0fQ=="
```


Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Page through customers from a database connection based pagination
query CustomersConnectionBased($first: Int!, $after: String = "") {
query Customers($first: Int!, $after: String = "") {
customers(first: $first, after: $after) {
edges {
node {
Expand Down
6 changes: 3 additions & 3 deletions dbquery/pagination/tests/Test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const {

testDescription = getTestDescription("snippets", __dirname);

const requestsFile = path.join(path.dirname(__dirname), "requests.graphql");
const requestsFile = path.join(path.dirname(__dirname), "operations.graphql");
const requests = fs.readFileSync(requestsFile, "utf8").toString();

describe(testDescription, function () {
Expand All @@ -18,7 +18,7 @@ describe(testDescription, function () {
{
label: "first set of results",
query: requests,
operationName: "CustomersConnectionBased",
operationName: "Customers",
variables: {
first: 2
},
Expand Down Expand Up @@ -49,7 +49,7 @@ describe(testDescription, function () {
{
label: "next set of results",
query: requests,
operationName: "CustomersConnectionBased",
operationName: "Customers",
variables: {
first: 2,
after: CURSOR
Expand Down