Simulating Subscriptions
@bboure I really appreciate your efforts in contributing to serverless-appsync-plugin and creating this awesome serverless-appsync-simulator plugin.
I'm facing problem testing subscriptions, I'm assuming subscription endpoint is ws://${IP_ADRESS}:20003/graphql
when I subscribe, a message "listening" continues to show up but on mutation, nothing would happen with a subscription(no data is received).
I'm using graphql explorer to test subscription.
Hi @Mudassir-23 To be honest, I have not used the subscription feature yet.
I will try to find some time to test and see if there are issues.
In any case, the problem is possibly in https://github.com/aws-amplify/amplify-cli since, this plugin is only a wrapper of it.
If you have some time and want to help, you can also try to debug and try to find the source of the problem
Historically AppSync was using MQTT not WebSocket to deliver subscriptions. That said support of WebSockets as a transport protocol was added quite recently: https://aws.amazon.com/about-aws/whats-new/2020/04/aws-appsync-enables-support-for-generic-websockets-clients-graphql-real-time-subscriptions/ There might be already some support for subscriptions in Amplify CLI, e.g. I see issue opened just today: https://github.com/aws-amplify/amplify-cli/issues/5798
Let's see if I can find some time and figure out what contribution needs to be done here.
Hi, any planned updates in implementing subscriptions?
@bboure Subscription with serverless-appsync-simulator work fine, its just that graphiql interface doesn't support the subscription testing yet. I was able to test subscription in dev through this example https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/aws-appsync%403.0.4/tutorials/react-offline-realtime-todos/src/App.js. I'm planning to clean up this example to make it generic and easy to understand, will post the link here soon. Again, I really appreciate your efforts in developing this plugin.
Hi @Mudassir-23 , Any way possible you can post more easier example here ?
It seems GraphiQL has supported subscriptions with a custom fetcher for some time now according to this blog post.
There is an update in the amplify project According to the CHANGELOG they have fixed mocking WS.
Note this changes are available in the latest version but for this we need to swicth from amplify-appsync-simulator to @aws-amplify/amplify-appsync-simulator
We tried today in our team via yarn resolutions "amplify-appsync-simulator": "npm:@aws-amplify/amplify-appsync-simulator@^2.6.1" and with a postinstall patch in ./node_modules/amplify-appsync-simulator/lib/data-loader/index.js
// Disabled since causing conflict somehow
//addDataLoader("AMAZON_ELASTICSEARCH"
This looks working fine, would love to see an update on this 😉
Thank you @Hideman85
If you got this working, please feel free to open a PR, that would be great.
Thanks