I have tried all solutions available on internet but don’t see apollo client working with appsync subscriptions with react v18. It works with queries and mutations only.
I am using these packages
[
"@apollo/client": "^3.10.3",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@iconify/react": "^4.1.1",
"@mui/material": "^5.15.1",
"amazon-cognito-identity-js": "^6.3.7",
"aws-appsync-auth-link": "^3.0.7",
"aws-appsync-subscription-link": "^3.1.2",
"axios": "^1.6.2",
"formik": "^2.4.5",
"graphql-tag": "^2.12.6",
"i18next": "^23.7.11",
"npm": "^10.2.5",
"react": "^18.2.0",
"react-cookie": "^6.1.1",
"react-dom": "^18.2.0",
"react-helmet-async": "^2.0.4",
"react-i18next": "^14.0.0",
"react-router-dom": "^6.21.1",
"react-scripts": "^5.0.1",
"simplebar-react": "^3.2.4",
"yup": "^1.3.3"
]
Here’s my client
const url = API_URL;
const region = "eu-west-2";
const auth = {
type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
jwtToken: async () => {
const { authToken } = await UserAuthService.getAuthTokens();
return `${authToken}`;
},
};
const httpLink = new HttpLink({ uri: API_URL });
const link = ApolloLink.from([
createAuthLink({ url, region, auth }),
createSubscriptionHandshakeLink(
{ url, region, auth, keepAliveTimeoutMs: 90000 },
httpLink
),
]);
const wsLink = new WebSocketLink(new SubscriptionClient(APPSYNC_WSS_URL));
const splitLink = split(
({ query }) => {
const definition = getMainDefinition(query);
const test =
definition.kind === "OperationDefinition" &&
definition.operation === "subscription";
console.log(`TESET RUESLT FOR QUERY `, test, query);
return test;
},
wsLink,
createAuthLink({ url, region, auth }).concat(httpLink)
);
export const client = new ApolloClient({
link: link,
cache: new InMemoryCache(),
});
// export const client = new ApolloClient({
// link: splitLink,
// cache: new InMemoryCache(),
// });
This is the error
enter image description here
Has anyone ever succeeded with work with appollo client and appsync subscriptions with react version 18?
I tried react-apollo but does not my react version.
I expected appsync subscriptions work
Bilal Syed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.