Nested query pagination not working

Here is the top level query:
const gift = await api.gifts.findFirst({
filter: {
giftId: { equals: giftId },
},
select: {
id: true,
giftLineItems: {
pageInfo: {
hasNextPage: true,
endCursor: true,
},
edges: {
node: GIFT_LINE_ITEM_SELECT,
},
},
...
const gift = await api.gifts.findFirst({
filter: {
giftId: { equals: giftId },
},
select: {
id: true,
giftLineItems: {
pageInfo: {
hasNextPage: true,
endCursor: true,
},
edges: {
node: GIFT_LINE_ITEM_SELECT,
},
},
...
Then I try to paginate gift line items like this:
while (hasNextPage) {
const response = await api.giftLineItem.findMany({
first: 250,
after: cursor,
filter: {
giftId: { equals: giftId },
gift: {
shopId: { equals: shopId },
},
},
select: GIFT_LINE_ITEM_SELECT,
});

allLineItems.push(...response);
hasNextPage = response.hasNextPage;
cursor = response.endCursor;
}
while (hasNextPage) {
const response = await api.giftLineItem.findMany({
first: 250,
after: cursor,
filter: {
giftId: { equals: giftId },
gift: {
shopId: { equals: shopId },
},
},
select: GIFT_LINE_ITEM_SELECT,
});

allLineItems.push(...response);
hasNextPage = response.hasNextPage;
cursor = response.endCursor;
}
But I'm getting the error below. Every time I've tried to paginate from a nested query I've got this error:
error:
message: Unexpected token 'a', "arrayconnection:49" is not valid JSON
name: SyntaxError
stack: SyntaxError: Unexpected token 'a', "arrayconnection:49" is not valid JSON
at JSON.parse (<anonymous>)
at decodeCursor (/app/packages/api/src/services/app-database/storage-strategies/cursors.js:25:17)
at SQLCursorPaginator.cursor (/app/packages/api/src/services/app-database/storage-strategies/durable/SQLCursorPaginator.js:258:50)
at SQLCursorPaginator.gellyWhereCondition (/app/packages/api/src/services/app-database/storage-strategies/durable/SQLCursorPaginator.js:116:29)
at SQLCursorPaginator.gellyCommandList (/app/packages/api/src/services/app-database/storage-strategies/durable/SQLCursorPaginator.js:94:37)
at SharedJSONTableStorageAdapter.gellyExpression (/app/packages/api/src/services/app-database/AppStorageAdapter.js:171:43)
at async SharedJSONTableStorageAdapter.modelSubQuery (/app/packages/api/src/services/app-database/storage-strategies/durable/SQLStorageAdapter.js:538:43)
...
error:
message: Unexpected token 'a', "arrayconnection:49" is not valid JSON
name: SyntaxError
stack: SyntaxError: Unexpected token 'a', "arrayconnection:49" is not valid JSON
at JSON.parse (<anonymous>)
at decodeCursor (/app/packages/api/src/services/app-database/storage-strategies/cursors.js:25:17)
at SQLCursorPaginator.cursor (/app/packages/api/src/services/app-database/storage-strategies/durable/SQLCursorPaginator.js:258:50)
at SQLCursorPaginator.gellyWhereCondition (/app/packages/api/src/services/app-database/storage-strategies/durable/SQLCursorPaginator.js:116:29)
at SQLCursorPaginator.gellyCommandList (/app/packages/api/src/services/app-database/storage-strategies/durable/SQLCursorPaginator.js:94:37)
at SharedJSONTableStorageAdapter.gellyExpression (/app/packages/api/src/services/app-database/AppStorageAdapter.js:171:43)
at async SharedJSONTableStorageAdapter.modelSubQuery (/app/packages/api/src/services/app-database/storage-strategies/durable/SQLStorageAdapter.js:538:43)
...
No description
No description
1 Reply
Chocci_Milk
Chocci_Milk3w ago
Hello, Could you please share the URL of the application so that I can test things out myself? Do you also mind if I make a new action to test this on?

Did you find this page helpful?