aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.41k stars 2.12k forks source link

Support `ws` for appsync realtime connection #12894

Open dominhhai opened 7 months ago

dominhhai commented 7 months ago

Is this related to a new or existing framework?

No response

Is this related to a new or existing API?

GraphQL API

Is this related to another service?

No response

Describe the feature you'd like to request

Support ws for realtime endpoint in order to test with appsync-simulator

Describe the solution you'd like

https://github.com/aws-amplify/amplify-js/blob/3629a7b8ec2bb06ddf885ee5ee18296dc93bcffb/packages/api-graphql/src/Providers/AWSAppSyncRealTimeProvider/index.ts#L751-L754

Change to ws if the input endpoint is http://,

                   // Creating websocket url with required query strings
                    discoverableEndpoint = discoverableEndpoint
                        .replace('https://', 'wss://')
                        .replace('http://', 'ws://');

Describe alternatives you've considered

Using the dangerously_connect_to_http_endpoint_for_testing flag to enable this feature

Additional context

No response

Is this something that you'd be interested in working on?

cwomack commented 7 months ago

Hello, @dominhhai and thank you for opening this issue. I'll mark this as a feature request at this point and review it with our team internally. If there's further questions or progress, we'll ping you in a new comment!

chrisbonifacio commented 3 months ago

Hi @dominhhai, could you explain your use case for this feature request a bit more so we can better understand how this might help?

This seems related to Amplify Gen 1's mocking feature which has been replaced by sandbox environments in Amplify Gen 2 so this may not be necessary anymore.

dominhhai commented 3 months ago

@chrisbonifacio

sandbox environments in Amplify Gen 2

Could you explain more detail about it?

dominhhai commented 3 months ago

@chrisbonifacio I checked the sandbox env. However, it is not what I wanted.

I want to work with local appsync such as appsync-simulator. The localhost is run on ws instead of wss. So it is nice if the amplify libs supports this case.