aws-mobile-appsync-sdk-js icon indicating copy to clipboard operation
aws-mobile-appsync-sdk-js copied to clipboard

Subscribe only available for AWS AppSync endpoint

Open phucnguyencong opened this issue 3 years ago • 0 comments

I get issues when using @apollo/client: 3.5.10, aws-appsync-auth-link: 3.0.7, aws-appsync-subscription-link: 3.0.10. There is my config

import { ApolloClient, ApolloLink, createHttpLink, InMemoryCache } from '@apollo/client';
import { createAuthLink } from 'aws-appsync-auth-link';
import { createSubscriptionHandshakeLink } from 'aws-appsync-subscription-link';
// Config
import { AWS_APPSYNC } from '../config';

const { graphqlEndpoint, region, apiKey } = AWS_APPSYNC;
const auth = {
  type: AWS_APPSYNC.authenticationType,
  apiKey: apiKey,
};

const httpLink = createHttpLink({ uri: graphqlEndpoint });
const link = ApolloLink.from([
  // @ts-ignore
  createAuthLink({ graphqlEndpoint, region, auth }),
  // @ts-ignore
  createSubscriptionHandshakeLink({ graphqlEndpoint, region, auth }, httpLink),
]);

export const client = new ApolloClient({
  link,
  cache: new InMemoryCache(),
});

and I am using

  const {
    data: subscription_message_data,
    loading: subscription_message_loading,
    error: subscription_message_error
  } = useSubscription(
    SUBSCRIPTION_NEW_MESSAGE, {
      variables: { conversationId: conversationId }
    });

But I got an error form useSubscription is: "Subscribe only available for AWS AppSync endpoint"

Does anyone have experience with this issue?

phucnguyencong avatar Apr 15 '22 08:04 phucnguyencong