amplify-js: Subscription not working in app (though it works on console), returning "null" all the time

Describe the bug

    const subscription = API.graphql(
      graphqlOperation(subscriptions.onCreateBank)
    ).subscribe({
      next: (eventData) => {
        console.log("new" + JSON.stringify(eventData.value.data));
      }
    });

Log always shows new{"onCreateBank":null}

while for the same new created object, console subscription shows

{ "data": { "onCreateBank": { "id": "6abcc124-8e83-4192-a331-de187b660f96", "name": "8abcdef", "__typename": "Bank" } } }

To Reproduce https://aws-amplify.github.io/docs/js/start?ref=amplify-rn-btn&platform=react-native

*Additional context Add any other context about the problem here. Windows 10

“dependencies”: { “aws-amplify”: “^2.2.2”, “aws-amplify-react-native”: “^3.2.0”, “react”: “16.9.0”, “react-native”: “0.61.5” },

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 19 (4 by maintainers)

Most upvoted comments

Found the problem/solution with the help of AWS support engineer. In case someone needs help…

Subscription only works in app if returned fields in corresponding mutation match with corresponding returned fields in subscription definition. If this is not the case, subscription would only work on console but not in APIs.

Its not documented anywhere…

I don’t like this solution, although it works. What if you make updates to fields as an admin and would like only some of the updated information propagated to real time users? This could be a security risk as a nefarious user would simply inspect their network tab to find compromising information if the data updated is not their own. Amplify needs to document this and change it, it’s not the GraphQL way.

It seems to working though in case the mutation returns the same structure as is expected in the subscription else the fields are returned null