opened 04:18PM - 31 May 18 UTC
closed 02:01PM - 01 Jun 18 UTC
Hello,
I have two front end apps using cognito login and an appsync api built… via serverless: https://github.com/ConduitVC/appsync-subscription-test
I am able to get subscriptions working, however, I am unable manipulate information in the subscription request resolver mapping.
schema.graphql
```
schema {
mutation: Mutation
query: Query
subscription: Subscription
}
type Query {
openQuoteRequests: [QuoteRequest]!
}
type Mutation {
requestQuote(quoteRequest: QuoteRequestInput!): QuoteRequest!
}
type Subscription {
subscribeToQuoteRequest: QuoteRequest!
@aws_subscribe(mutations: ["requestQuote"])
}
enum quoteRequestStatus {
Cancelled
Open
Filled
Closed
}
type QuoteRequest {
id: String!
customerId: String!
commodity: String!
amount: Int!
status: quoteRequestStatus!
}
input QuoteRequestInput {
commodity: String!
amount: Int!
}
```
Mutation request resolver:
```
#if($context.identity.sub)
#set( $values = $ctx.args.quoteRequest.put("customerId", "${context.identity.sub}") )
#set( $values = $ctx.args.quoteRequest.put("status", "Open") )
{
"version" : "2017-02-28",
"operation" : "PutItem",
"key": {
"id" : $util.dynamodb.toDynamoDBJson($util.autoId())
},
"attributeValues": $util.dynamodb.toMapValuesJson($context.arguments.quoteRequest)
}
#else
$utils.unauthorized()
#end
```
Subscription request resolver
```
{
"version": "2017-02-28",
"payload": {
"id": "${ctx.args.id}",
"amount": 5,
"commodity": "${ctx.args.commodity}",
"customerId": "${ctx.args.customerId}",
}
}
```
Subscription response resolver
```
$util.toJson($ctx.result)
```
The `amount` is ignored in the request mapping above. In the subscription response to the client, `amount` is the original value from the mutation instead of `5`. The same result occurs when the request resolver simply forwards ctx.args, and the response is comprised of the payload above.