# Apsync subscription lambda resolver

**URL:** <https://forum.serverless.com/t/apsync-subscription-lambda-resolver/6642>\
**Category:** Serverless Architectures\
**Tags:** api-gateway\
**Created:** [December 3, 2018, 9:22pm UTC](https://forum.serverless.com/t/apsync-subscription-lambda-resolver/6642 "2018-12-03T21:22:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SET001](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/set001/32/2638_2.png) [@SET001](https://forum.serverless.com/u/SET001)\
**Post date:** [December 3, 2018, 9:22pm UTC](https://forum.serverless.com/t/apsync-subscription-lambda-resolver/6642/1 "2018-12-03T21:22:18Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [December 10, 2018, 12:54pm UTC](https://forum.serverless.com/t/apsync-subscription-lambda-resolver/6642/2 "2018-12-10T12:54:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SET001](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/set001/32/2638_2.png) [@SET001](https://forum.serverless.com/u/SET001)\
**Post date:** [December 10, 2018, 4:11pm UTC](https://forum.serverless.com/t/apsync-subscription-lambda-resolver/6642/3 "2018-12-10T16:11:40Z")

</div>

can you please show a link on where they said this

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [December 10, 2018, 8:56pm UTC](https://forum.serverless.com/t/apsync-subscription-lambda-resolver/6642/4 "2018-12-10T20:56:52Z")

</div>

> [@SET001](#):
>
> can you please show a link on where they said this

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

---

<div class="post-metadata">

**Author:** ![SET001](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/set001/32/2638_2.png) [@SET001](https://forum.serverless.com/u/SET001)\
**Post date:** [December 10, 2018, 9:10pm UTC](https://forum.serverless.com/t/apsync-subscription-lambda-resolver/6642/5 "2018-12-10T21:10:09Z")

</div>

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

 ![apsyncsubsciptions](https://canada1.discourse-cdn.com/flex036/uploads/serverless/original/2X/d/d659d1676c9b8d783961ecd5c50e31087d081e9f.png)  
despite the fact that I chose `id` in subscription, I will get `cost` because it was selected in mutation. Is it expected behavior?

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [December 10, 2018, 9:43pm UTC](https://forum.serverless.com/t/apsync-subscription-lambda-resolver/6642/6 "2018-12-10T21:43:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![SET001](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/set001/32/2638_2.png) [@SET001](https://forum.serverless.com/u/SET001)\
**Post date:** [December 11, 2018, 5:56am UTC](https://forum.serverless.com/t/apsync-subscription-lambda-resolver/6642/7 "2018-12-11T05:56:13Z")

</div>

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](https://canada1.discourse-cdn.com/flex036/uploads/serverless/original/2X/b/b6482daad11c69d6d10f04527cf897a4c5e3b1dd.png)

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…
