Created
April 16, 2018 17:13
-
-
Save undefobj/dadd09540ddc090db1be320af4c185ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//DynamoDB table with Primary Key "id" and each item has attributes "title" and "author | |
//If you have an item in the table that only has one of these attributes, the search will fail | |
//Use the below GraphQL schema: | |
type Post { | |
id: ID! | |
title: String! | |
author: String! | |
} | |
type Query { | |
searchByCity(title: String!): [Post] | |
} | |
//Attach a resolver with the following filter on the request template to look for items that match your input value for title | |
{ | |
"version" : "2017-02-28", | |
"operation" : "Scan", | |
"filter" : { | |
"expression" : "contains(#title, :title)", | |
"expressionNames" : { | |
"#title" : "title" | |
}, | |
"expressionValues" : { | |
":title" : $util.dynamodb.toDynamoDBJson($ctx.args.title) | |
} | |
} | |
} | |
//The response template in the resolver will pass back the results that match: | |
$util.toJson($ctx.result.items) | |
//Now you can run a query and any items that have "Hello" in the title will be returned: | |
query { | |
searchByCity(title:"Hello"){ | |
id | |
title | |
author | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment