New to mongodb + aws combination and struggling to expand on a few great javascript resolvers created for this blog (listApplicants, addApplicants)–> The fullstack guide to using AWS AppSync and MongoDB Atlas | Front-End Web & Mobile
The blog examples above run fine. Tried to add “get a single applicant” resolver set up and I can’t seem to deploy it even after reviewing aws lambda/api examples. Similar with delete and update.
Here’s my toy code.
import { util } from '@aws-appsync/utils';
// https://www.mongodb.com/developer/products/atlas/atlas-data-api-aws-lambda/
export function request(ctx) {
// how to grab id
const id = ctx.args.id;
return {
method: 'POST',
version: '2018-05-29',
resourcePath: '/app/data-foofoo/endpoint/data/v1/action/findOne',
params: {
headers: {
'api-key': secret,
'Content-Type': 'application/json',
'Access-Control-Request-Headers': '*',
Accept: 'application/json',
},
body: {
dataSource: 'foo-example-Cluster0',
database: 'applicationEmployment',
collection: 'employmentForm',
//prettier-ignore
// projection: { '_id': ObjectId(id) },
projection: { _id: id },
},
},
};
}
export function response(ctx) {
console.log(ctx.result.body);
// const record = JSON.parse(ctx.result.body).documents;
// const record = JSON.parse(ctx.result.body);
// console.log(record);
// return record;
if (res.id) {
//// return ctx.stash.applicantData;
return res;
} else {
util.error('record failed to be inserted');
}
}
Thanks in advance.