Apsync subscription lambda resolver

api-gateway

#1

I have created a mutation and a subscription to that mutation. Unless I did not select a resolver for that subscription - everything is working fine. This is what called local resolver, right?

But, say, I need some logic to be done for data formatting before give it to subscriber. I have added an lambda for that and set it as data source an resolver for this subscription. But this lambda only triggered once - when I creating subscription in graphql playground. Then it newer triggers again as mutation runs again and again.

What might be the reason of such behavior? If this is expected?


#2

I can’t help much beyond confirming that’s how AppSync works. Even AWS has said this.


#3

can you please show a link on where they said this


#4

Not without spending a lot of time searching for one. If you need a link then I would start at the Github issues for aws-amplify or aws-mobile-appsync-sdk-js


#5

can you maybe comment another strange situation I got with subscriptions: - whatever data structure I request in subscription, every time I will only got fields specified in mutation


despite the fact that I chose id in subscription, I will get cost because it was selected in mutation. Is it expected behavior?


#6

This is expected too. Only the fields passed to the mutation are available in the subscription. It’s the way AppSync works.


#7

The subscription is need to have a selection of subfields. There is an error if I don’t select any. But if I do, they just ignored. This all looks very strange…

appsyncselectionsubfields

This also means that I can’t actually control what data would be passed to subscriber. I might have same mutation to be triggered with different subfields by different clients, the single subscriber would have different data in those cases then. Looks inconsistent…