Skip to content
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

ES Request Template - Mutation Return Type #18

Closed
sid88in opened this issue Jan 21, 2018 · 2 comments
Closed

ES Request Template - Mutation Return Type #18

sid88in opened this issue Jan 21, 2018 · 2 comments

Comments

@sid88in
Copy link

sid88in commented Jan 21, 2018

Schema:

type Tweet {
  tweet: String
}

type Mutation {
  # Create a tweet for a user
  createUserTweet(
    name: String!,
    screen_name: String!,
    location: String!,
    description: String!,
    followers_count: Int!,
    friends_count: Int!,
    favourites_count: Int!,
    post: String!
  ): Tweets

}

type Tweets {
  name: String!
  screen_name: String!
  location: String!
  description: String!
  followers_count: Int!
  friends_count: Int!
  favourites_count: Int!
  posts: [Tweet]
}

schema {
  mutation: Mutation
}

Request Template:

{
    "version":"2017-02-28",
    "operation":"PUT",
    "path":"/user/twitter/$util.autoId()",
    "params":{
        "body":{
            "name":"$context.arguments.name",
            "screen_name":"$context.arguments.screen_name",
            "location":"$context.arguments.location",
            "description":"$context.arguments.description",
            "followers_count":$context.arguments.followers_count,
            "friends_count":$context.arguments.friends_count,
            "favourites_count":$context.arguments.favourites_count,
            "tweet": "$context.arguments.post"
        }
    }
}

Response Template:

$utils.toJson($context.result.get("_source"))

Query:

screen shot 2018-01-21 at 2 07 14 pm

Question:

  1. Not sure why I am getting output in the first place because ES response doesn't have _source fields.

  2. Because I am getting the response (as pointed in 1) not sure why posts is null?

  3. In this mutation, all I should need is screen_name and tweet but I have to post other fields as well because I don't know a way to first GET the fields for a given screen name and then use those fields in the PUT object in response mapping as pointed in Multiple Operations in the same appsync request template #17

any help would be great.
thanks
Sid

@sid88in
Copy link
Author

sid88in commented Jan 21, 2018

Interestingly what works is this:

Request mapping template:

{
    "version":"2017-02-28",
    "operation":"PUT",
    "path":"/user/twitter/$util.autoId()",
    "params":{
        "body":{
            "name":"$context.arguments.name",
            "screen_name":"$context.arguments.screen_name",
            "location":"$context.arguments.location",
            "description":"$context.arguments.description",
            "followers_count":$context.arguments.followers_count,
            "friends_count":$context.arguments.friends_count,
            "favourites_count":$context.arguments.favourites_count,
            "posts": [{"tweet": "$context.arguments.post"}]
        }
    }
}

Query:
screen shot 2018-01-21 at 2 13 37 pm

But my ES schema doesn't have posts object (in the first screenshot). So is there no way we can do this mapping in the response mapping layer?

@sid88in
Copy link
Author

sid88in commented Jan 22, 2018

last solution worked so closing this ticket.

@sid88in sid88in closed this as completed Jan 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant