This guide will help you upgrade your application from aws-appsync-auth-link v3.x and aws-appsync-subscription-link v3.x to v4.x.
Version 4 of the AWS AppSync Apollo links brings compatibility with Apollo Client v4 and includes several important updates:
- ✅ Apollo Client v4 support
- ✅ GraphQL v16 support
- ✅ Dual module format (ESM + CommonJS)
- ✅ Browser environment compatibility improvements
- ✅ RxJS v7+ peer dependency
- ✅ UUID peer dependency (for subscription-link)
v3:
{
"dependencies": {
"@apollo/client": "^3.2.0"
}
}v4:
{
"dependencies": {
"@apollo/client": "^4.0.0"
}
}You must upgrade to Apollo Client v4. Follow the official Apollo Client v4 migration guide for details on Apollo-specific changes.
v4 requires GraphQL v16 (previously v15 was supported).
Update your dependencies:
npm install graphql@^16.0.0
# or
yarn add graphql@^16.0.0Both packages now have RxJS as a peer dependency. If you don't already have it installed:
npm install rxjs@^7.0.0
# or
yarn add rxjs@^7.0.0The aws-appsync-subscription-link package now requires UUID as a peer dependency. If you don't already have it installed:
npm install uuid@^8.0.0
# or
yarn add uuid@^8.0.0Note: UUID v9 and v10 are also supported if you prefer newer versions.
Due to Apollo Client v4 requirements, ensure you're using:
- Node.js 14.16+ or higher
Update your package.json:
{
"dependencies": {
"@apollo/client": "^4.0.0",
"aws-appsync-auth-link": "^4.0.0",
"aws-appsync-subscription-link": "^4.0.0",
"graphql": "^16.0.0",
"rxjs": "^7.0.0",
"uuid": "^8.0.0"
}
}Note: If you're only using aws-appsync-auth-link (queries/mutations without subscriptions), you don't need to install uuid.
Then install:
npm install
# or
yarn installApollo Client v4 has some import changes. The most common:
Before (v3):
import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client';After (v4):
// Same imports work, but check Apollo's migration guide for any
// specific features you're using
import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client';Your client setup remains largely the same:
import { createAuthLink } from 'aws-appsync-auth-link';
import { createSubscriptionHandshakeLink } from 'aws-appsync-subscription-link';
import {
ApolloClient,
InMemoryCache,
HttpLink,
ApolloLink,
} from '@apollo/client';
const url = 'https://xxxxx.appsync-api.us-east-1.amazonaws.com/graphql';
const region = 'us-east-1';
const auth = {
type: 'API_KEY', // or 'AWS_IAM' | 'AMAZON_COGNITO_USER_POOLS' | 'OPENID_CONNECT' | 'AWS_LAMBDA'
apiKey: 'da2-xxxxxxxxxxxxxxxxxxxxxxxxxx',
// For Cognito or OIDC:
// jwtToken: async () => 'your-jwt-token',
// For IAM:
// credentials: async () => credentials,
};
const httpLink = new HttpLink({ uri: url });
const link = ApolloLink.from([
createAuthLink({ url, region, auth }),
createSubscriptionHandshakeLink({ url, region, auth }, httpLink),
]);
const client = new ApolloClient({
link,
cache: new InMemoryCache(),
});Solution: This issue has been fixed in v4. If you're still seeing it, ensure you've:
- Installed v4.0.0 or higher
- Cleared your
node_modulesand reinstalled - Rebuilt your application
Solution: v4 now properly supports ESM. Ensure you're using the latest version and that your bundler is configured to resolve the exports field in package.json.
Solution:
- Update
@types/graphqlif you have it installed - Ensure your
tsconfig.jsonhas proper module resolution:
{
"compilerOptions": {
"moduleResolution": "node",
"esModuleInterop": true
}
}Solution: The uuid package is now a peer dependency for aws-appsync-subscription-link. Install it:
npm install uuid@^8.0.0
# or
yarn add uuid@^8.0.0If you're only using aws-appsync-auth-link for queries/mutations, you don't need uuid.
When migrating to Apollo Client v4, be aware of these key changes:
Apollo Client v4 uses RxJS instead of zen-observable:
// v3 - zen-observable
import { Observable } from 'zen-observable-ts';
// v4 - RxJS (usually not needed in user code)
import { Observable } from 'rxjs';Some cache methods have changed. Refer to the Apollo Client v4 migration guide for details.
After upgrading, test these key areas:
Test all auth types you're using:
// API Key
const auth = {
type: 'API_KEY',
apiKey: 'your-api-key',
};
// IAM
const auth = {
type: 'AWS_IAM',
credentials: async () => ({
accessKeyId: 'xxx',
secretAccessKey: 'xxx',
sessionToken: 'xxx',
}),
};
// Cognito User Pools
const auth = {
type: 'AMAZON_COGNITO_USER_POOLS',
jwtToken: async () => 'your-jwt-token',
};
// OIDC
const auth = {
type: 'OPENID_CONNECT',
jwtToken: async () => 'your-jwt-token',
};
// Lambda
const auth = {
type: 'AWS_LAMBDA',
token: async () => 'your-token',
};import { gql, useQuery } from '@apollo/client';
const GET_ITEMS = gql`
query GetItems {
listItems {
items {
id
name
}
}
}
`;
function MyComponent() {
const { loading, error, data } = useQuery(GET_ITEMS);
if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error.message}</p>;
return <div>{/* Render your data */}</div>;
}import { gql, useMutation } from '@apollo/client';
const CREATE_ITEM = gql`
mutation CreateItem($input: CreateItemInput!) {
createItem(input: $input) {
id
name
}
}
`;
function MyComponent() {
const [createItem, { data, loading, error }] = useMutation(CREATE_ITEM);
const handleCreate = () => {
createItem({ variables: { input: { name: 'New Item' } } });
};
return <button onClick={handleCreate}>Create</button>;
}import { gql, useSubscription } from '@apollo/client';
const ON_CREATE_ITEM = gql`
subscription OnCreateItem {
onCreateItem {
id
name
}
}
`;
function MyComponent() {
const { data, loading, error } = useSubscription(ON_CREATE_ITEM);
if (loading) return <p>Listening...</p>;
if (error) return <p>Error: {error.message}</p>;
return <div>{/* Render subscription data */}</div>;
}If you're using React Native:
- Ensure you have the proper polyfills for
fetchand WebSocket - Apollo Client v4 may have additional React Native requirements - check the Apollo docs
If you encounter issues, you can rollback to v3:
npm install @apollo/client@^3.2.0 aws-appsync-auth-link@^3.0.0 aws-appsync-subscription-link@^3.0.0 graphql@^15.0.0
# or
yarn add @apollo/client@^3.2.0 aws-appsync-auth-link@^3.0.0 aws-appsync-subscription-link@^3.0.0 graphql@^15.0.0Note: In v3, uuid was bundled with aws-appsync-subscription-link, so you can uninstall it if you added it for v4.
If you encounter issues during migration:
- Check the GitHub Issues
- Review the AWS AppSync Forum
- Open a new issue with:
- Your package versions
- Error messages
- Minimal reproduction code
Beyond the breaking changes, v4 includes:
- Better Bundle Size: Proper externalization of dependencies (including uuid) reduces bundle size
- Improved Browser Compatibility: No more Node.js polyfills in browser bundles
- Modern Module Format: Full ESM support with backwards-compatible CommonJS
- Updated Dependencies: Latest security patches and improvements
- Optimized Peer Dependencies: Common packages like uuid are now peer dependencies to avoid duplication
Last Updated: 2025-10-12