Closed carolynwang closed 3 years ago
Any updates on this error? We are currently running into the same issue
Also running into this problem; any help would be appreciated!
Hey @carolynwang, thank you for opening this issue.
I am going to take a look at this issue to see if I can uncover what seems to be the root cause
I have the same issue in Angular AppSync Subscriptions just dont work Returning errors as 'message: "AppSync Realtime subscription init error: undefined" Documetation does not help at all, being at this issue for the last 10 days
+1 Encountered the same issue on a Vue app which is subscribing to multiple subscriptions.
Hi @evcodes, are there any updates on this issue?
Yes, I was not able to reproduce your issue after following the getting started guide. However, I do believe there may be some issues with how you setup your mutations/subscriptions. I have not looked into this much yet.
@carolynwang looks like you're subscribing to a onAddEmail
mutation when your schema defined it as onAddInfo
?
@chrisbonifacio Sorry, I edited our actual code and schema to make it simpler for this github issue and forgot to change it to onAddInfo
. I've edited the description to say onAddInfo
now.
For clarification, the API was not created with the Amplify CLI but was created directly in the AppSync console (Create API -> Create with wizard), which generated a default schema. I did some experiments and all the default mutation/subscriptions (create, modify, and delete) also return null in the react native app but works perfectly in the AppSync console.
I set the same schema that was shared with a None type data source. Ran a mutation through AppSync console, which seemed to work.
subscribed to mutation on AppSync console, which also seemed to work
However, subscribing to the mutation in a React Native app did not reproduce the issue. The subscription resulted in:
My graphql/subscriptions.js
file
export const onAddInfo = /* GraphQL */ `
subscription OnAddInfo($one: String, $two: String, $three: String) {
onAddInfo(one: $one, two: $two, three: $three) {
one
two
three
}
}
`;
React Native code:
useEffect(() => {
const sub = API.graphql(graphqlOperation(onAddInfo)).subscribe({
next: subOnAddInfo => {
console.log(subOnAddInfo.value); // should return null for the onAddItem field
// should return TypeError: null is not an object
setItems(items => [...items, subOnAddInfo.value.data.onAddInfo]);
},
error: error => console.warn(error),
});
return () => sub.unsubscribe();
}, []);
@carolynwang please see @chrisbonifacio's comment above. Does this match your implementation? Thanks!!
@david-mcafee @chrisbonifacio @evcodes Just tried it again (without changing anything) and it is suddenly working now. Thanks for your help on this!
Hi Guys, i have fixed it in my end (Angular) hope this helps:
1) Amplify needs to use Auth method from aws-amplify not @aws-amplify
2) Amplify.configure(exports) is all you need (also import from aws-amplify)
3) You can use amazon-cognito-identity-js library to create a custom user and attributes
4) Use default API.Service which is autogenerated cause it has a bit of complexity
5) Subscription must use this format:
this.subscriptionv =
Hence you need Subscription from rxjs not appsync Subscription (a bit weird) 6) For reads you can simply call API.graphql, but for writes you can use default api and will do all the handling for you (if this does not work it means something is misconfigured and appsync/amplify wont tell you) 7) Configuration of amazon cognito user pools must have ALLOW_ADMIN_USER_PASSWORD_AUTH 8) Use client idp as well (starting with 4-XXXX rather than the 5/6-xxxx) 9) Make sure your cognito credentials load faster than the creation of the network socket, -> ngAfterViewInit can help with this. 10) Validate all custom lambdas (AWS Cloud) to return all declared values 11) Now socket should run smoothly, if not create a testing CRUD with default libraries, often package.json contains imports which are not needed or clash between them,making a painful import of methods in components
You can use appsync console to generate the schema, thus importing schema with amplify codegen
command (see console)
@carolynwang Awesome! Glad it's working 😄 There have been some issues in the past where the fields being returned in the mutation need to match the fields in the subscription. If they don't match, the subscription will receive null
for the fields that were not returned by the mutation.
@david-mcafee @chrisbonifacio @evcodes Just tried it again (without changing anything) and it is suddenly working now. Thanks for your help on this!
I am having the this problem for mutations, I did not touch graphql at all but suddenly this API started to convert the args to null.
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server amplify-help
forum.
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
GraphQL API
Amplify Categories
api
Environment information
Describe the bug
The bug we are seeing seems to be same as the one described in https://github.com/aws-amplify/amplify-js/issues/4832, however the solution that was provided did not work for us.
We are building a ReactNative app, using AppSync mutations and subscriptions, and using the Amplify API. We have tested the subscriptions in the AppSync console, and it is successfully returns a correct response when we fire the corresponding mutation. When we call the same subscription in JS, the response we get is null. This is true for both our custom mutation/subscriptions and the ones that were autogenerated for us.
Expected behavior
Return all the requested data.
Reproduction steps
type Query { getInfo(one: String!, two: String!): info }
type Subscription { onAddInfo(one: String, two: String, three: String): info @aws_subscribe(mutations: ["addItem"]) }
type info { one: String two: String three: String }
schema { query: Query mutation: Mutation subscription: Subscription }
{ "version": "2017-02-28", "payload": $util.toJson($context.args) }
$util.toJson($context.result)
Log output
aws-exports.js
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response