I'm using this page as a starting point.
My code looks like this:
app.get('/gizmos', async (req, res, next) => {
const pageSize = 3;
const resText = [];
const cursor = req.query.cursor;
try {
let query = datastore.createQuery('gizmo').limit(pageSize);
if (cursor) {
query = query.start(cursor);
}
const [results] = await datastore.runQuery(query);
const [gizmos] = results[0];
const info = results[1];
if (info.moreResults !== Datastore.NO_MORE_RESULTS) {
// If there are more results to retrieve, the end cursor is
// automatically set on `info`. To get this value directly, access
// the `endCursor` property.
const nextUrl = req.protocol + "://" + req.get("host") + req.baseUrl + "?cursor=" + info.endCursor;
console.log(nextUrl);
}
gizmos.forEach(gizmo => {
const id = gizmo[Datastore.KEY].id;
resText.push({
"id" : id,
"name" : gizmo.name,
});
});
res
.status(200)
.set('Content-Type', 'text/plain')
.send(resText)
.end();
} catch (error) {
next(error);
}
});
But it fails with a 500
error. The logs say this:
Error: 13 INTERNAL: Request message serialization failure: invalid encoding at Object.callErrorFromStatus (/workspace/node_modules/@grpc/grpc-js/build/src/call.js:31:26)
at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client.js:176:52)
at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:336:141) at Object.onReceiveStatus (/workspace/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:299:181) at /workspace/node_modules/@grpc/grpc-js/build/src/call-stream.js:145:78 at processTicksAndRejections (internal/process/task_queues.js:75:11)
Any ideas?
console.log(nextUrl);
? If so then the query is being executed correctly and the reason might be what was commented above. – Rafael Lemos