I would like to return the ImageSet type from the AddImageSet mutation. But I seem to be unable to do this because each field on my ImageSet type has it's own resolver, which is overwriting the resolver mapping template.
Schema:
type ImageSet {
SetKey: ID
SetName: String
SetCreatedAt: AWSTimestamp
SetDescription: String
SetTags: [Tag]
}
type Mutation {
AddImageSet(setName: String!, setDescription: String): ImageSet
}
Here is the mutation:
{
"version" : "2017-02-28",
"operation" : "PutItem",
"key" : {
"PartitionKey" : { "S" : "ImageSet" },
"SortKey" : { "S" : "ImageSet-$util.autoId()" }
},
"attributeValues" : {
"Name": { "S" : "${context.arguments.setName}" },
"Description": { "S" : "${context.arguments.setDescription}" },
"CreatedAt": { "N" : $util.time.nowEpochSeconds() },
}
}
and the response mapping template
{
"SetKey" : "$context.result.SortKey",
"SetName" : "$context.result.Name",
"SetCreatedAt" : $context.result.CreatedAt,
"SetDescription" : "$context.result.Description"
}
When I run this, the object returned by AddImageSet mutation has every field set as null, because the field resolvers are overwriting the response mapping template of the AddImageSet mutation.
I have solved this by creating a duplicate 'ImageSetResult' type, just without resolvers attached to the field. Then if the AddImageSet Mutation returns that, everything is just fine. But these seems kind of redundant.
Is there a better way to do this?