I get issues when using @apollo/client: 3.5.10, aws-appsync-auth-link: 3.0.7, aws-appsync-subscription-link:3.0.9 and 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 SUBSCRIPTION_NEW_MESSAGE = gql`
subscription subscribeToNewMessage($conversationId: ID!) {
subscribeToNewMessage(conversationId: $conversationId) {
content
createdAt
id
senderCognitoId
}
}
`
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 from useSubscription is: “Subscribe only available for AWS AppSync endpoint”.
Does anyone have experience with this issue?