I have the following Schema:
input CreateEventInput {
userID: String!
eventID: ID!
type: String!
data: String
dateTime: AWSDateTime!
}
type Mutation {
createEvent(input: CreateEventInput!): event
}
type Subscription {
onCreateEvent(): event
@aws_subscribe(mutations: ["createEvent"])
The createEvent
resolver sets the userID
like:
"key" : {
"userID" : $util.dynamodb.toDynamoDBJson($context.identity.username),
"eventID" : $util.dynamodb.toDynamoDBJson($util.autoId())
}
I'd like to limit the subscription so that only records where the userID = $context.identity.username
are returned to the user.
Does anyone know how to set this up? I think I need a resolver on the subscription, but I can't find a clear example of this where you have a Primary partition key (userID
) and Primary sort key (eventID
).
I would really appreciate any help or guidance. I can change the schema or DB if needed.
Update:
I believe I can set the Subscription Response Mapping Template to something like:
#if(${context.identity.username} != ${context.arguments.userID})
$utils.unauthorized()
#else
##User is authorized, but we return null to continue
null
#end
However, I'm at a loss what to put in the Request Mapping Template.