#✅ - Amplify subscription not working.. (WebSocket connection to`ws://...` failed)

7 messages · Page 1 of 1 (latest)

opaque parcel
#

It does work in appsync (using subscription directly in appsync works but not in my react ionic app). Ive tried everything.. here is the code:

  const onCreateUserConversation = /* GraphQL */ `
  subscription OnCreateUserConversation(
    $filter: ModelSubscriptionUserConversationFilterInput
  ) {
    onCreateUserConversation(filter: $filter) {
      id
    }
  }
`;
const subscribeUserConversationCreate = () => {
  const subscription = API.graphql<
    GraphQLSubscription<OnCreateUserConversationSubscription>
  >({
    query: subscriptions.onCreateUserConversation,
    authMode: "API_KEY",
  }).subscribe({
    next: ({ value }) => console.log(value),
    error: (error) => console.error(error),
  });

  return subscription;
};

useEffect(() => {
  getConversations();

  console.log("subscribing to convo create");
  const subscription = subscribeUserConversationCreate();

  return () => subscription.unsubscribe();
}, []);

The mutation from appsync

mutation MyMutation {
  createUserConversation(
    input: {
      userId: "adeldueast",
      conversationId: "9f80911e-c221-4474-b92d-922d4d8b2174"
    }) {
    id
  }
}

And finally my schema:

type User @model {
  id: ID!
  username: String
  conversations: [Conversation] @manyToMany(relationName: "UserConversation")
}
type Conversation @model {
  id: ID!
  name: String!
  users: [User] @manyToMany(relationName: "UserConversation")
  messages: [Message] @hasMany(indexName: "byConversation", fields: ["id"])
}
type Message @model {
  id: ID!
  conversationID: ID!
    @index(name: "byConversation", sortKeyFields: ["createdAt"])
  owner: String!
  content: MessageContent!
  createdAt: AWSDateTime
}
type MessageContent {
  text: String
  media: S3Object
}
type S3Object {
  bucket: String!
  region: String!
  key: String!
}
opaque parcel
#

Fixed it. I deleted amplify backend and re pulled the project. When asked what kind of framework im using i selected Ionic instead of react and it worked.

plush plaza
#

be carefull with the option "aws_appsync_dangerously_connect_to_http_endpoint_for_testing" in the aws-exports if is value is true the appsync subscription only work in localhost, this has to be false for deployment

fleet patioBOT
#

✅ - Amplify subscription not working.. (WebSocket connection tows://... failed)

#

Answer selected!
Fixed it. I deleted amplify backend and re pulled the project. When asked what kind of framework im using i selected Ionic instead of react and it worked.
Kudos to @opaque parcel!
#1147971718346981376 message

livid solar
#

Module '"@aws-amplify/api"' has no exported member 'API'