The `aws-appsync-auth-link` package provides a specialized Apollo Link for integrating AWS AppSync authentication with Apollo Client in JavaScript and TypeScript applications. It is part of the `aws-mobile-appsync-sdk-js` repository and is currently at version 4.0.2. This link allows developers to configure various AWS AppSync authentication modes, including API Key, AWS IAM, Amazon Cognito User Pools, and OpenID Connect, by injecting the necessary authentication headers into GraphQL requests. Its primary differentiator is its seamless integration with the Apollo Client ecosystem, abstracting away the complexities of signing requests for AppSync. The package's release cadence tends to align with major Apollo Client versions, with a significant jump from v1 to v4 to maintain compatibility with `@apollo/client` v3.x and v4.x, implying potentially infrequent but impactful updates.
npm install aws-appsync-auth-linkVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize Apollo Client with `aws-appsync-auth-link` and `aws-appsync-subscription-link` for an AppSync API using API Key authentication. It correctly chains the necessary Apollo Links and configures the client.
Migrate your Apollo Client setup to v3.x or v4.x, ensuring `InMemoryCache` and `HttpLink` are correctly imported from `@apollo/client` and links are chained appropriately. Refer to Apollo Client migration guides.
Ensure your `config` object passed to `createAuthLink` includes `url`, `region`, and a correctly structured `auth` object matching your AppSync API's authentication type, including necessary credentials (e.g., `apiKey`, `jwtToken`, `credentials`).
Install `aws-appsync-subscription-link` (`npm install aws-appsync-subscription-link`) and integrate `createSubscriptionHandshakeLink` into your Apollo Link chain, usually before the `httpLink`.
Ensure the config object passed to `createAuthLink` includes a valid 'region' string, e.g., `{ url: '...', region: 'us-east-1', auth: {...} }`.Verify the validity and expiry of your authentication credentials (e.g., API Key, JWT token). For IAM roles, ensure the attached policy grants necessary access to the AppSync API. Double-check your AppSync API's authentication settings in the AWS console.
Ensure all links (`authLink`, `subscriptionLink`, `httpLink`) are correctly instantiated and not `null` before chaining them together using `.concat()`. Check your imports and configuration parameters for any typos or missing values.
Install the required peer dependency: `npm install @apollo/client graphql rxjs`