0

My APPSync is connected to a dynamodb table and the schema looks like this:

type Query {
    getNews(date: String!): News
    listNews(filter: TableNewsFilterInput, limit: Int, nextToken: String): NewsConnection
}
input TableNewsFilterInput {
    date: TableStringFilterInput
    news: TableStringFilterInput
}

input TableStringFilterInput {
    ne: String
    eq: String
    le: String
    lt: String
    ge: String
    gt: String
    contains: AWSJSON
    notContains: String
    between: [String]
    beginsWith: String
}

The news column in the dynamodb table is a map and looks something like this:

{
abhijit banerjee:{
ampUrlString:   https://m.freepressjournal.in/article/business/rahul-gandhi-and-abhijit-banerjee-discuss-economic-crisis-amid-coronavirus-pandemic-here-are-the-highlights-of-their-conversation/5a5c3e42-9a55-4fce-8ac3-5b4a17125aca
}
}

I need to filter using a keyword, say, Abhijit. I couldn't find the solutions anywhere. Any help appreciated!

1 Answers1

0

You can use Query to get the data and then apply a filter. Something like this:

    {
        "version" : "2017-02-28",
        "operation" : "Query",
        "query" : {
            "expression": "primaryKey = :primary", ## add a sort key filter if the table has it
            "expressionValues" : {
                ":primaryKey" : $util.dynamodb.toDynamoDBJson($ctx.args.primaryKey)
            }
        },
        "filter" : {
            "expression": "contains (:name, name)",
            "expressionValues" : {
                ":authors" : $util.dynamodb.toDynamoDBJson($ctx.args.name)
            }
        }
    }

You can also create an index on the news column. Add only one key in in the index and project all columns in it. Now you can use query with this index, this will help if you want all news related to one input string.

Also check here: Querying DynamoDB with a list in AWS AppSync

Praneet Nadkar
  • 823
  • 7
  • 16