Mapping template for self referencing object
See original GitHub issueSchema:
type Query {
getUserTwitterFeed(handle: String!): User!
}
type Tweet {
tweet_id: String!
tweet: String!
retweeted: Boolean!
retweet_count: Int
favorited: Boolean!
created_at: String!
}
type TweetConnection {
items: [Tweet!]!
nextToken: String
}
type User {
name: String!
handle: String!
followers: [User]
tweets(limit: Int, nextToken: String, keyword: String): TweetConnection
}
schema {
query: Query
}
Data Source:
Hashkey = handle
sortKey = tweet_id
attributes : name, tweet, tweet_id, retweeted..
I have a mapping template associated with User and tweet given below
User:
{
"version" : "2017-02-28",
"operation" : "Query",
"query" : {
## Provide a query expression. **
"expression": "handle = :handle",
"expressionValues" : {
":handle" : {
"S" : "${context.arguments.handle}"
}
}
}
}
tweets:
{
"version": "2017-02-28",
"operation": "Query",
"query": {
"expression": "handle = :handle",
"expressionValues": {
":handle": {
"S": "$context.source.handle"
}
}
},
"limit": #if($context.arguments.limit) $context.arguments.limit #else 10 #end,
"nextToken": #if($context.arguments.nextToken) "$context.arguments.nextToken" #else null #end
#if(${context.arguments.keyword})
,"filter": {
"expression": "begins_with (#tweet, :keyword)",
"expressionNames" : {
"#tweet" : "tweet"
},
"expressionValues": {
":keyword": { "S": "${context.arguments.keyword}" }
}
}
#end
}
Note: the above filter expression is not working explained here but for this particular question lets not worry about it.
Question: How do I handle self-referencing User in followers: [User]. Each user can have a list of followers stored as string in the database attribute for example: followers : [“sid”, “gupta”]
Now when we query dynamo via GraphQL we fetch data for a given handle but each handle/user can have multiple followers and we might want to get data for each follower as well.
I am trying to look into Batch Get Item. Something like this:
{
"RequestItems": {
"users": {
"Keys": [
{
"handle":{"S":"sid"} -- $context.source.followers[0]
},
{
"Name":{"S":"gupta"} -- $context.source.followers[1]
}
],
"ProjectionExpression":"tweet, retweet_count"
}
},
"ReturnConsumedCapacity": "TOTAL"
}
Is this kind of query supported by GraphQL? Not sure how to proceed here.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
Top Results From Across the Web
C++ map -- Self referencing iterator - Stack Overflow
The main trick is to defer definition of a member variable type until after definition of the enveloping class. This is achieved by...
Read more >Hibernate: Modeling Self-referencing Associations - YouTube
When you model a hierarchical data structure, you often have to use self - referencing associations. Both ends of these associations are of ......
Read more >Resolver mapping template overview - AWS AppSync
Resolver mapping template overview for AWS AppSync. ... Unit resolvers are self-contained entities which include a request and response template only.
Read more >Working with Self-Referencing Tables in Master-Detail Browser
Viewing Data in a Self-Referencing Table · Click Master-Detail Browser on the Database Tools toolbar. · Drag'n'drop the Employees table you've created onto...
Read more >Modeling self-referencing associations with Hibernate
In other words, the entity object on which the association is defined and the one the association references are of the same type....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@sid88in Regarding filtering, I added a new comment to that thread. Basically, we have a fix out so you should retry the filtering!
It worked 😄:D thanks!!!