In AWS AppSync, arguments send on the main query don't seem to be forwarded to all children resolvers.
type Query {
article(id: String!, consistentRead: Boolean): Article
book(id: String!, consistentRead: Boolean): Book
}
type Article {
title: String!
id: String!
}
type Book {
articleIds: [String]!
articles: [Article]!
id: String!
}
when I call:
query GetBook {
book(id: 123, consistentRead: true) {
articles {
title
}
}
}
the first query to get the book receives the consistentRead
param in $context.arguments
, but the subsequent query to retrieve the article does not. ($context.arguments
is empty)
I also tried articles(consistentRead: Boolean): [Article]!
inside book
but no luck.
Does anyone know if it's possible in AppSync to pass arguments to all queries part of the same request?
It is possible to pass arguments from parent to child via the response. Let me explain ...
AppSync has several containers inside
$context
:arguments
andstash
are always cleared before invoking a child resolver as evident from these Cloudwatch logs:At the very end of the parent execution -
arguments
andstash
data are present.and then at the very beginning of the child resolver -
arguments
andstash
are always blank.Workaround 1 - get the argument from the previous result.
In the example above
device
is always present in the response of the parent resolver, so I insertedinto the request mapping template of the child resolver. It will try to get the ID it needs from the arguments and then fall back onto the previous result.
Workaround 2 - add the argument to the parent response
Modify your parent resolver response template to include the arguments:
and then retrieve it in the request mapping template of the child the same way as in the first workaround.