aws / aws-appsync-community

The AWS AppSync community
https://aws.amazon.com/appsync
Apache License 2.0
506 stars 32 forks source link

Subscriptions Without Websockets #17

Open tylermakin opened 5 years ago

tylermakin commented 5 years ago

In building a recent B2B webapp, we discovered that some corporate networks block websockets. Similarly, some proxies cause websockets to appear open but do not allow any data through. Appsync cannot be used in these situations because its subscriptions rely on websockets without a fallback.

Appsync needs to support an alternative to websockets for passing real-time data through subscriptions where websockets cannot be used.

See this Stack Overflow question for details.

vlekakis commented 5 years ago

Thanks again for opening the issue here!

tylermakin commented 5 years ago

I opened another issue because this error is not handled properly by the Amplify API and a fallback cannot be built until this error is recognized and handled: Bug: GraphQL subscriptions do not throw error on websocket failure

KoldBrewEd commented 4 years ago

Give it a try with our new WebSockets implementation, it should return an error: https://aws.amazon.com/blogs/mobile/appsync-realtime/

bpceee commented 4 years ago

Give it a try with our new WebSockets implementation, it should return an error: https://aws.amazon.com/blogs/mobile/appsync-realtime/

Hi @awsed , this might be a separate issue.
But for this new pure WebSocket thing, what if we use a custom domain name for appsync address? There is no appsync-api in our custom domain name, therefore no appsync-realtime-api either.

KoldBrewEd commented 4 years ago

If you want to use the new pure WebSockets support your client must connect to the appsync-realtime-api endpoint. If you're using the AppSync SDK or Amplify clients they will automatically detect the endpoints. If you are not using the default endpoints on your client then you'll have to do it in your code manually as AppSync does not have built-in support for custom domains yet.

bpceee commented 4 years ago

Thanks @awsed , I guess we need two domains. One as appsync-api.domain.com another as appsync-realtime-api.domain.com. Just for matching the AppSync SDK .

patrick-michelberger commented 4 years ago

@bpceee we faced the same problem. As a workaround, we configured the Apollo client manually using AppSync's subscription link using "MQTT over Websockets" https://github.com/awslabs/aws-mobile-appsync-sdk-js/blob/master/packages/aws-appsync-subscription-link/src/subscription-handshake-link.ts.

import { createAuthLink } from 'aws-appsync-auth-link';
import { createSubscriptionHandshakeLink } from 'aws-appsync-subscription-link';

import { ApolloLink } from 'apollo-link';
import { createHttpLink } from 'apollo-link-http';
import ApolloClient from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';

import appSyncConfig from "./aws-exports";

const url = appSyncConfig.aws_appsync_graphqlEndpoint;
const region = appSyncConfig.aws_appsync_region;
const auth = {
  type: appSyncConfig.aws_appsync_authenticationType,
  apiKey: appSyncConfig.aws_appsync_apiKey,
};

const httpLink = createHttpLink({ uri: url });

const link = ApolloLink.from([
  createAuthLink({ url, region, auth }),
  createSubscriptionHandshakeLink(url, httpLink)
]);

const client = new ApolloClient({
  link,
  cache: new InMemoryCache()
})
jpignata commented 2 years ago

The feature request here is to offer a long polling endpoint that uses HTTP sans WebSockets? Please :+1: if this would be helpful for you!

deejvince commented 1 year ago

Bump, any update?