Skip to content

Commit 6510652

Browse files
Merge pull request #76 from stepzen-dev/offset_ex_test
chore: fix offset example and the test
2 parents 23c009b + 35be7aa commit 6510652

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

rest/pagination/api.graphql

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ type Query {
145145
resultroot: "values[]"
146146

147147
# Ecmascript (with empty endpoint) is used to mimic the response from a REST api.
148-
# Note ECMAScript is only used to generate a mock response with customer objects and page number metadata,
148+
# Note ECMAScript is only used to generate a mock response with customer objects and offset metadata,
149149
# using @rest against a real endpoint would not typically require any ECMAScript.
150150
endpoint: "stepzen:empty"
151151
ecmascript: """
152152
function transformREST() {
153153
// A total of 23 items will be returned
154-
const totalItems = 23;
154+
const records = 23;
155155
156156
// Pagination field arguments
157157
// Since this is OFFSET pagination
@@ -161,12 +161,9 @@ type Query {
161161
const limit = get('first');
162162
const offset = get('after');
163163
164-
// metadata - total number of records
165-
const records = Math.ceil(totalItems / limit)
166-
167164
// generate customers for nodes based on the limit and offset values
168165
const startIndex = offset+1 || 1;
169-
const endIndex = Math.min(startIndex + limit, totalItems+1);
166+
const endIndex = Math.min(startIndex + limit, records+1);
170167
var customers = []
171168
for (let i = startIndex; i < endIndex; i++) {
172169
customers.push({
@@ -180,7 +177,7 @@ type Query {
180177
// when pagination is through an offset.
181178
// @rest must be configured to match the REST response layout.
182179
//
183-
// pagination setters defines that the page count
180+
// pagination setters defines that total number of records
184181
// is taken from meta.records
185182
//
186183
// resultroot corresponds to the location that contains the

rest/pagination/requests.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ query CustomersPageNumber($first: Int!, $after: String) {
1515
}
1616
}
1717

18-
# Page through customers from a REST API using page numbers
18+
# Page through customers from a REST API using offset
1919
query CustomersOffset($first: Int!, $after: String) {
2020
customersOffset(first: $first, after: $after) {
2121
edges {

rest/pagination/tests/Test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe(testDescription, function () {
111111
pageInfo: {
112112
endCursor:
113113
"eyJjIjoiTzpRdWVyeTpjdXN0b21lcnNPZmZzZXQiLCJvIjo5fQ==",
114-
hasNextPage: false,
114+
hasNextPage: true,
115115
},
116116
},
117117
},
@@ -130,7 +130,7 @@ describe(testDescription, function () {
130130
pageInfo: {
131131
endCursor:
132132
"eyJjIjoiTzpRdWVyeTpjdXN0b21lcnNPZmZzZXQiLCJvIjoxOX0=",
133-
hasNextPage: false,
133+
hasNextPage: true,
134134
},
135135
},
136136
},

0 commit comments

Comments
 (0)