This is possible in AppSync today.
To accomplish this, you could add a query field to your schema called getUser (getUser makes more sense than getFeeds in this case) and it would have a resolver which retrieves a User object from a data source.
type Query {
getAllUsers(limit: Int): [User]
getUser(id:ID!): User
}
Then, you can also add resolvers on the User.following and User.userFeed fields. The User.following resolver would query your data source and retrieve users whom somebody is following. The User.userFeed resolver would query your data source to retrieve a list of user feeds.
Both of these resolvers (User.following and User.userFeed) should utilize $context.source in the resolver's request mapping template. This variable will contain the result of your getUserresolver. The request mapping template's job is to create a query which your data source understands.
An example request mapping template which might be attached to User.following could be similar to the following. It would query a table named "Following", which has a primary partition key of id (the id of the user):
{
"version" : "2017-02-28",
"operation" : "Query",
"query" : {
## Provide a query expression. **
"expression": "id = :id",
"expressionValues" : {
":id" : {
## Use the result of getUser to populate the query parameter **
"S" : "${ctx.source.id}"
}
}
}
}
You would have to do something similar for User.userFeed resolver.
After you're all setup, you can run the below query, and the following will happen:
query {
getUser(id:"myUserId") {
following {
userFeed {
id
ImageDataUrl
textData
date
}
}
}
}
- getUser resolver will run first. It will query your User data source and retrieve the user.
- User.following resolver will run. It will use the result of it's parent field resolver (getUser) to query the data source for following.
- User.userFeed resolver will run. It will use the result of it's parent field resolver (getUser) to query the user feed data source.