question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mapping template for self referencing object

See original GitHub issue

Schema:

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:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
mlshoncommented, Jan 27, 2018

@sid88in Regarding filtering, I added a new comment to that thread. Basically, we have a fix out so you should retry the filtering!

0reactions
sid88incommented, Jan 27, 2018

It worked 😄:D thanks!!!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found