So I want to simulate a SELECT * FROM TABLE WHERE ID IN {LIST_OF_IDS}
query, I know Im using a NoSQL database (dynamoDB) but I have an index on the field for which I want to execute this query. So mainly I want to get all the posts from a user where the userID (index column) is the given list.
I am using Amplify as my managed backend and using graphql as my API. I know there is no IN
keyword to use for graphql (at least nog APPSYNC). I have tried creating a custom resolver from a template provided by AWS like the following
import { util } from '@aws-appsync/utils';
/**
* Gets items from the DynamoDB tables in batches with the provided `id` keys
* @param {import('@aws-appsync/utils').Context} ctx the context
* @returns {import('@aws-appsync/utils').DynamoDBBatchGetItemRequest} the request
*/
export function request(ctx) {
return {
operation: 'BatchGetItem',
tables: {
Posts: {
keys: ctx.args.ids.map((id) => util.dynamodb.toMapValues({ id })),
consistentRead: true,
},
},
};
}
/**
* Returns the BatchGetItem table items
* @param {import('@aws-appsync/utils').Context} ctx the context
* @returns {[*]} the items
*/
export function response(ctx) {
if (ctx.error) {
util.error(ctx.error.message, ctx.error.type);
}
return ctx.result.data.Posts;
}
But this doesnt seem to work. I would also like to avoid to run a query for each user in the list to retrieve the posts. All help is greatly appreciated, also if you have another architectural solution/proposal to solve this issue I am all ears!