-
Notifications
You must be signed in to change notification settings - Fork 364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance appsync dynamodb example with multiple table relationships #248
Comments
Hi :), Finally successfully implemented with dynamodb + mapping templates. Unfortunately I don't have time for a full PR, but I post small explanation here (since it's been a pain to find something related to this on the AWS doc) The key is to link mapping templates through the "source" argument. See here: https://docs.aws.amazon.com/appsync/latest/devguide/resolver-context-reference.html#dynamodb-helpers-in-util-dynamodb In my case, I have an Image, which contains Objects, with two distinct dynamoDB Tables. I would like to query something like this:
where id, name, hash and path are stored in one table, and objects in another My YAML looks like this:
To be noted: the primary key for an object in the Objects table is the same as the primary key of the image. However, this is not necessary for this example. My mapping templates look like this: getImagesList:
and infos:
The key point is 'source' :). Hope it helps, it took me an entire week to understand how to get parents arguments :) ! PS: there is another example of source in 'topTweet-request-mapping-template.txt' |
@eltonio450 thanks a lot! I'll take a look sometime this week. |
@sid88in @eltonio450 Hi, I have same problem. I have two tables. User and Post and I need get post and information about author. User.userId = Post.userId. Could you help me ?
and I have next response:
but if use "${ctx.args.userId}" instead "${ctx.source.userId}" I have
|
Hi, First, you need to slightly modify your request to include userId on the 'items' level (which then will be passed in 'source' to the next level):
Then, you should have two mapping templates: One which resolves 'items' in PostConnection (or directly listUserPosts), and should look like this (not tested, modified yours), with Post as Datasource.
At this point, you collected all the posts given a userId You now need to resolve the field 'author' for every item. The mapping template, with User as Datasource, will look like this (if you don't have a sort key on your Users table):
(btw you can batchInvoke here) Hope it helps |
Hi i have some issue in app sync api type Query { type User { schema { // QUERY and my Request Mapping Template Code |
Hi @eltonio450
Here, if $context.source.userId will be null or empty, what about? |
In response to anyone trying to query two different Dynamo tables to access related data: In this manner we are using partitions effectively. DynamoDB will actually store items with the same partition key physically close together in memory. Now when we want to get post data as well as data about a user we can do it in one query. If we just want posts and no user data we make the following query: PK=userId:1, SK begins_with(postId). I think it makes the query a lot simpler too. Taking this pattern even further, having Id's becomes kind of pointless. Instead of having post Id's we can throw that out and use timestamps instead. Now we can execute queries like partitionKey=01 and sortKey greater_than() will give us all a user's posts within a time range. This will be a lot faster, cheaper, and maintainable than provisioning and querying two separate tables. good talk on this topic here |
Is there a way in Appsync to write a recursive function.. Something like iterate over a loop of record gratear than 1 MB from the data source in appsync , process all the records and then push it to client ? |
No description provided.
The text was updated successfully, but these errors were encountered: