Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS App Sync Subscriptions not working because of MQTT error

I am calling this graphql subscription on my react app:

export const OnCreateMessage = `
  subscription OnCreateMessage($conversationId: ID!) {
    onCreateMessage(messageConversationId: $conversationId) {
      id
      content
      authorId
      messageConversationId
      createdAt
    }
  }
`

This is how I call it inside a class component:

API.graphql(
    graphqlOperation(subscriptions.OnCreateMessage, {conversationId: "c074c7b7-f6db-459a-a1d8-cd290aee33ea"})
  ).subscribe({
    next: ({ provider, value }) => console.log({provider, value}),
    error: error => console.warn("did not get messages")
});

However, when I run my app and this is called, I get this error on my network tab:

{
  "errors" : [ {
    "errorType" : "BadRequestException",
    "message" : "Subscriptions over MQTT is not supported."
  } ]
}

I saw on the AWS docs that "MQTT over WebSockets will no longer be available for new AppSync APIs" but I don't know what to do now.

Can someone look into this and help me out?

like image 330
Mikey K Avatar asked Apr 03 '21 20:04

Mikey K


People also ask

How do AppSync subscriptions work?

Subscriptions in AWS AppSync are invoked as a response to a mutation. This means that you can make any data source in AWS AppSync real time by specifying a GraphQL schema directive on a mutation. The AWS Amplify client libraries automatically handle subscription connection management.

What is AppSync resolver?

Data sources and resolvers are how AWS AppSync translates GraphQL requests and fetches information from your AWS resources. AWS AppSync has support for automatic provisioning and connections with certain data source types.

How do you use subscriptions in GraphQL?

Open your favorite browser and navigate to http://localhost:3000/graphql, you will see the playground UI appear, so run the subscription. The playground will start listening to event updates from the GraphQL server. Create a second tab and load http://localhost:3000/graphql on it.

What is AWS App Sync?

AWS AppSync provides a robust, scalable GraphQL interface for application developers to combine data from multiple sources, including Amazon DynamoDB, AWS Lambda, and HTTP APIs.


1 Answers

I'm not sure if you found an answer to this, but we are facing the same thing with a project and it requires that you use a GraphQL client that can handle subscriptions over pure WebSockets. See the answer to this question about using the AWS AppSync client.

like image 122
Adam Greene Avatar answered Sep 17 '22 18:09

Adam Greene